public ActionResult SaveUpdatedItem(Item updatedItem) { //1. Create the ORM Coffee_Shop_DBEntities ORM = new Coffee_Shop_DBEntities(); //2. Find the Item OldItemRecord = ORM.Items.Find(updatedItem.Name); // Validation if (OldItemRecord != null && ModelState.IsValid) { //3. Update the existing customer OldItemRecord.Name = updatedItem.Name; OldItemRecord.Description = updatedItem.Description; OldItemRecord.Price = updatedItem.Price; // flip state to "modified" ORM.Entry(OldItemRecord).State = System.Data.Entity.EntityState.Modified; // 4. Save back to the Database ORM.SaveChanges(); return(RedirectToAction("Admin")); } else { ViewBag.ErrorMessage = "Oops! Something went wrong!"; return(View("Error")); } }
public ActionResult Edit([Bind(Include = "ID,Description,Quantity,Price,Items")] Coffee_Shop_DB coffee_Shop_DB) { if (ModelState.IsValid) { db.Entry(coffee_Shop_DB).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(coffee_Shop_DB)); }