public ActionResult UpdatePost(Product product, string Id, HttpPostedFileBase file) { if (!ModelState.IsValid) { var item = context.Find(Id); return(View(item)); } var productToUpdate = context.Find(Id); if (productToUpdate != null) { if (file != null) { productToUpdate.Image = product.Id + Path.GetExtension(file.FileName); file.SaveAs(Server.MapPath("//Content//Image//") + productToUpdate.Image); } productToUpdate.Name = product.Name; productToUpdate.Description = product.Description; productToUpdate.Price = product.Price; productToUpdate.Category = product.Category; //productToUpdate.Image = product.Image; context.Edit(productToUpdate); context.Commit(); return(RedirectToAction("List")); } else { return(new HttpNotFoundResult("Not Found")); } }
public ActionResult UpdatePost(ProductCategory ProductCategory, string Id) { if (!ModelState.IsValid) { var item = context.Find(Id); return(View(item)); } var productToUpdate = context.Find(Id); if (productToUpdate != null) { productToUpdate.Category = ProductCategory.Category; context.Edit(productToUpdate); context.Commit(); return(RedirectToAction("List")); } else { return(new HttpNotFoundResult("Not Found")); } }