Exemple #1
0
        public void AddProduct(AddProductInputServiceModel model)
        {
            var product = this.mapper.Map <Product>(model);

            this.context.Products.Add(product);
            this.context.SaveChanges();
        }
Exemple #2
0
        public IActionResult Create(CreateProductInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.RedirectToAction("Error", "Home"));
            }
            AddProductInputServiceModel serviceModel =
                this.mapper.Map <AddProductInputServiceModel>(model);

            this.productService.AddProduct(serviceModel);
            return(this.RedirectToAction("All"));
        }
Exemple #3
0
 public void AddProduct(AddProductInputServiceModel model)
 {
     try
     {
         Product product = this.mapper.Map <Product>(model);
         this.dbContext.Products.Add(product);
         this.dbContext.SaveChanges();
     }
     catch (Exception)
     {
         throw new ArgumentException(ExceptionMessages.InvalidProductType);
     }
 }