public void EditProduct(string id, EditProductInputServiceModel model) { try { Product product = this.mapper.Map <Product>(model); Product productToUpdate = this.dbContext.Products.Find(id); if (productToUpdate == null) { throw new ArgumentException(ExceptionMessages.ProductNotFound); } productToUpdate.Name = product.Name; productToUpdate.ProductType = product.ProductType; productToUpdate.Price = product.Price; this.dbContext.SaveChanges(); } catch (ArgumentException ae) { throw ae; } catch (Exception) { throw new ArgumentException(ExceptionMessages.InvalidProductType); } }
public IActionResult Edit(ProductEditViewModel model) { if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } EditProductInputServiceModel serviceModel = this.mapper.Map <EditProductInputServiceModel>(model); this.productService.EditProduct(model.Id, serviceModel); return(this.RedirectToAction("All")); }