bassed on prodinner project (decimal mapping failed)

Sep 25, 2014 at 8:50 PM
Edited Sep 25, 2014 at 8:51 PM
Hello,

I tried to apply onion architecture on a sample project of mine based on prodinner and I'm facing issues when working with decimal fields in DTO inputs.

Tried to change to double and it doesn't save to db in mapping class only integer fields are able to save and retrieve.

Note that I tired the decimal on tables with nullable decimals and required decimals options too.
Coordinator
Sep 26, 2014 at 8:47 AM
you're probably haivng trouble mapping from dtos to entities, which is done using the valueinjecter and mapping classes, have you read the prodinner.pdf ?
you can also read about the valueinjecter
Sep 28, 2014 at 8:11 AM
I did, and using value-injections MaptoInput, mapTop entity, every thing in mapping goes well except for decimal fields.
Coordinator
Sep 28, 2014 at 8:59 AM
well, that means your not handling that type, for example if in the entity you have Amount:decimal and in the ViewModel Amount:int and you don't have logic to transform from decimal to int, it won't work
Sep 29, 2014 at 11:28 PM
I've tried it on prodinner by adding nullable decimal field to chef table, it is working but the UI of decimal field is not good, thus I had to change the following:
  1. Adding new template to Shared/EditorTemplates (Decimal.aspx)
  2. Inject attribute (data-decimal="1") to textbox in runtime.
    (I should have an attribute like = Numaric(True) inside awesomeTextBox :( which I can't right now)
  3. Add [UIHint("Decimal")] to Input-Class
  4. Adding extra function to AwesomeMVC,js
    awe.numeric(a.d); now I have awe.decimalValue(a.d);
    as below:
numeric: function (a) {
            a.keydown(function (a) {
                var c = a.which; 46 == c || (8 == c || 9 == c || 27 == c || 13 == c || 65 == c && !0 === a.ctrlKey || 35 <= c && 39 >= c) || ((48 > c || 57 < c) && (96 > c || 105 < c) ? a.preventDefault() : !0 === a.shiftKey && k(a));
            });
        }, decimalValue: function (a) {
            a.keypress(function (a) {
                var c = a.which;$(this).val($(this).val().replace(/[^0-9\.]/g, ''));
                if ((c != 46 || $(this).val().indexOf('.') != -1) && (c < 48 || c > 57)) {a.preventDefault();}
            });
            a.keyup(function (a) {
                var c = a.which;$(this).val($(this).val().replace(/[^0-9\.]/g, ''));
                if ((c != 46 || $(this).val().indexOf('.') != -1) && (c < 48 || c > 57)) {a.preventDefault();}
            });
            a.blur(function (a) {
                var c = a.which;$(this).val($(this).val().replace(/[^0-9\.]/g, ''));
                if ((c != 46 || $(this).val().indexOf('.') != -1) && (c < 48 || c > 57)) {a.preventDefault();}
            });
        }
btw Thanks for your great efforts in prodinner (Y)
Marked as answer by OldTrain on 9/29/2014 at 3:28 PM