public ProductDTO Create(ProductDTO createDTO) { ProductDTO returnDTO = new ProductDTO(); Product productEntity = new Product(); var config1 = new MapperConfiguration(cfg => { cfg.CreateMap <ProductDTO, Product>(); }); IMapper mapper1 = config1.CreateMapper(); productEntity = productDAL.Create(mapper1.Map <ProductDTO, Product>(createDTO)); var config2 = new MapperConfiguration(cfg => { cfg.CreateMap <Product, ProductDTO>(); }); IMapper mapper2 = config2.CreateMapper(); returnDTO = mapper2.Map <Product, ProductDTO>(productEntity); return(returnDTO); }
public int Create(Product product) { return(ProductDAL.Create(product)); }
static void Main() { var context = new LojaZeroDbContextFactory().CreateDbContext(); var pro = new ProductDAL(context); var cli = new ClientDAL(context); var product = new Product() { Name = "sorvete", Description = "sorvete muito bom", Stock = 10, Value = 1.3m, Weight = 1, ProductTags = new List <ProductTag>() { new ProductTag() { Tag = new Tag() { Name = "Comida" } }, new ProductTag() { Tag = new Tag() { Name = "delicia" } } } }; var client = new Client() { FirstName = "Felipe", LastName = "pinheiro", CPF = "012.109.651-35", DtBirthDay = new DateTime(1985, 5, 1), Gender = Gender.Male, User = new UserPerson() { Email = "*****@*****.**", Password = "******" }, Phones = new List <Phone>() { new Phone() { AreaCode = 61, CountryCode = 55, Number = 995599415 } }, Addresses = new List <Address>() { new Address() { Country = "brasil", State = "DF", City = "Brasilia", District = "taguatiga", Number = 25, Street = "qnb 03", ZipCode = 72115030 } } }; pro.Create(product); cli.Create(client); Console.WriteLine(pro.Exist(1)); }