public ActionResult Edit(Product product) { if (ModelState.IsValid) { var dbProduct = context.Products.FirstOrDefault(x => x.Id == product.Id); dbProduct.Name = product.Name; dbProduct.Description = product.Description; dbProduct.Price = product.Price; dbProduct.Category = product.Category; dbProduct.LastModifiedOn = DateTime.Now; context.SaveChanges(); return RedirectToAction("Products"); } return View(product); }
public ActionResult AddProduct(Product product) { if (ModelState.IsValid) { var prod = new Product() { Name = product.Name, Description = product.Description, Price = product.Price, Category = product.Category, CreatedOn = DateTime.Now }; this.context.Products.Add(prod); this.context.SaveChanges(); return RedirectToAction("Products"); } return View(product); }