public void Create([FromBody] Product product) { if (product != null) { service.UpdateProduct(product); } }
public IActionResult ProductEdit(ProductEditViewModel model) { if (ModelState.IsValid) { Product product = new Product { Discontinued = model.Discontinued, ProductID = model.ProductID, ProductName = model.ProductName, QuantityPerUnit = model.QuantityPerUnit, ReorderLevel = model.ReorderLevel, UnitPrice = model.UnitPrice, UnitsInStock = model.UnitsInStock, UnitsOnOrder = model.UnitsOnOrder, Supplier = service.Suppliers.FirstOrDefault(s => s.CompanyName == model.Supplier), Category = service.Categories.FirstOrDefault(c => c.CategoryName == model.Category), CategoryID = service.Categories.FirstOrDefault(c => c.CategoryName == model.Category).CategoryID, SupplierID = service.Suppliers.FirstOrDefault(s => s.CompanyName == model.Supplier).SupplierID }; service.UpdateProduct(product); return(RedirectToAction("Products")); } else { return(View(model)); } }