public IActionResult ProductEdit(int id) { var model = new ProductEditViewModel(); var product = service.Product(id); if (product == null) { product = new Product { CategoryID = service.Categories.FirstOrDefault().CategoryID, SupplierID = service.Suppliers.FirstOrDefault().SupplierID, }; } model.Category = service.Categories.FirstOrDefault <Category>(c => c.CategoryID == product.CategoryID).CategoryName; model.Discontinued = product.Discontinued; model.ProductID = product.ProductID; model.ProductName = product.ProductName; model.Supplier = service.Suppliers.FirstOrDefault <Supplier>(s => s.SupplierID == product.SupplierID).CompanyName; model.QuantityPerUnit = product.QuantityPerUnit; model.UnitPrice = product.UnitPrice; model.UnitsInStock = product.UnitsInStock; model.UnitsOnOrder = product.UnitsOnOrder; model.ReorderLevel = product.ReorderLevel; model.suppliers = service.Suppliers.Select(s => s.CompanyName); model.categories = service.Categories.Select(c => c.CategoryName); return(View(model)); }
public void Delete(int id) { var product = service.Product(id); if (product != null) { service.DeleteProduct(id); } }