public ActionResult Edit(Category Category) { if (ModelState.IsValid) { var Categor = db.Category.SingleOrDefault(c => c.id == Category.id); Categor.name = Category.name; db.Entry(Categor).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult New(ProductCategoryModel pc) { if (ModelState.IsValid) { if (pc.file != null) { String img = System.IO.Path.GetFileName(pc.file.FileName); String path = System.IO.Path.Combine(Server.MapPath("~/images/Products/"), img); pc.file.SaveAs(path); pc.Product.image = img; } db.Product.Add(pc.Product); db.SaveChanges(); var categories = db.Category.SingleOrDefault(c => c.id == pc.Product.CategoryId); categories.number_of_products++; db.Entry(categories).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("Index")); }