public void SaveProduct(Product product) { if (product.ProductId == 0) { context.Products.Add(product); } else { Product dbEntry = context.Products.Find(product.ProductId); if (dbEntry != null) { dbEntry.Name = product.Name; dbEntry.Description = product.Description; dbEntry.Price = product.Price; dbEntry.Category = product.Category; } } context.SaveChanges(); }
public ActionResult Index(Product product) { _productRepository.SaveProduct(product); return View(_productRepository.Products); }