MVC DDD Project

Asked

Viewed 113 times

0

I’m creating an application, using the DDD standard, so in my Presentation layer, I create viewModel, and in the controller I use the Mapper.Map<Entidade, EntidadeViewModel> . i would like to know the following. in my domain, I use some Enuns, I need to create the Viewmodel of these Enuns? Actually, I did, but it didn’t work out. Follow the Code Enum:

public enum EstadoViewModel
    {
        [Description("Rondônia")]
        RO = 11,
        [Description("Acre")]
        AC = 12,
        [Description("Amazonas")]
        AM = 13,
        [Description("Roraima")]
        RR = 14,
        [Description("Pará")]
        PA = 15,
        [Description("Amapá")]
        AP = 16,
        [Description("Tocantins")]
        TO = 17,
        [Description("Maranhão")]
        MA = 21,
        [Description("Piauí")]
        PI = 22,
        [Description("Ceará")]
        CE = 23,
        [Description("Rio Grande do Norte")]
        RN = 24,
        [Description("Paraíba")]
        PB = 25,
        [Description("Pernambuco")]
        PE = 26,
        [Description("Alagoas")]
        AL = 27,
        [Description("Sergipe")]
        SE = 28,
        [Description("Bahia")]
        BA = 29,
        [Description("Minas Gerais")]
        MG = 31,
        [Description("Espírito Santo")]
        ES = 32,
        [Description("Rio de Janeiro")]
        RJ = 33,
        [Description("São Paulo")]
        SP = 35,
        [Description("Paraná")]
        PR = 41,
        [Description("Santa Catarina")]
        SC = 42,
        [Description("Rio Grande do Sul")]
        RS = 43,
        [Description("Mato Grosso do Sul")]
        MS = 50,
        [Description("Mato Grosso")]
        MT = 51,
        [Description("Goiás")]
        GO = 52,
        [Description("Distrito Federal")]
        DF = 53

    }

That way you’re saving it in the bank on my chart that gets Enum, like 0. So, do I need to create the enumViewModel? or just use the Enum from the same domain layer? thus adding a reference in my Presentation layer to the domain layer.

1 answer

2


Open topic long time huh! Already managed to solve? Come on, the good thing would be for you to isolate the Enumerators in another project of the solution, fixing in the application layer, because you can come to use in other projects of the solution, Let’s say that you will be using a new typification of attribute and reference in the projects to which they will make use of it.

In the domain the field of the entity you will submit you can declare as the created Enum:

EstadoViewModel estado{ get; set;} 

for the bank will be recognized as Int.

But if you don’t want to create in this template you can handle your Enum in the Presentation layer and in the domain put the field as Int.

In your mapping your Enum you must do the conversion to Int. So it will go to the bank correctly.

  • I already solved.. I put the enums separately, and use them in any part of the proejto.. ie mine ClienteDominio.Enum has the same One as the ClienteViewModel.Enum. So far I had no problem using so. Thanks!!

  • Ball Show. Now that I’ve seen your post.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.