public ActionResult SaveChanges(item UpdatedItem) { lab24Entities ORM = new lab24Entities(); // find the old record item OldRecord = ORM.Items.Find(UpdatedItem.itemID); //To Do: check for null if (OldRecord == null) { return(RedirectToAction("Index")); } OldRecord.Name = UpdatedItem.Name; OldRecord.Description = UpdatedItem.Description; OldRecord.Quantity = UpdatedItem.Quantity; OldRecord.Price = UpdatedItem.Price; ORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveNewItem(item newItem) { lab24Entities ORM = new lab24Entities(); //To Do: Validation! ORM.Items.Add(newItem); ORM.SaveChanges(); // sync with the database return(RedirectToAction("Index")); }
public ActionResult DeleteItem(int itemID) { lab24Entities ORM = new lab24Entities(); // for loop to find the id // find is a method that is used to find objects by using the primary key item ItemToDelete = ORM.Items.Find(itemID); // remove ORM.Items.Remove(ItemToDelete); ORM.SaveChanges(); // To Do: use try catch return(RedirectToAction("Index")); }