public void AddProduct(AddProductInputServiceModel model) { var product = this.mapper.Map <Product>(model); this.context.Products.Add(product); this.context.SaveChanges(); }
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")); }
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); } }