public ActionResult SaveChanges(item updatedItem) //update { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //find the old record that you're updating item OldRecord = ORM.items.Find(updatedItem.itemid); //ToDo: check for null!!!!!! //if (OldRecord == null) //{ // return View("Index"); //} //don't need to update itemid because that stays the same OldRecord.name = updatedItem.name; OldRecord.description = updatedItem.description; OldRecord.quantity = updatedItem.quantity; OldRecord.price = updatedItem.price; //need to change the state of the record from original to the modified state!! ORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult SaveChanges(User newUser) { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); ORM.Users.Add(newUser); ORM.SaveChanges(); return(RedirectToActionPermanent("Products")); }
public ActionResult SaveNewItem(item newItem) //add { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //ORM... needed for anytime you talk to db (found in index) // ToDo: data validation!!! if statement ORM.items.Add(newItem); //adding newItem obj to the form serverside ORM.SaveChanges(); //sync with the database and show the changes and what is saved return(RedirectToAction("Index")); //bounce back to index to show the list of items we have }
public ActionResult SaveNewItem(item newItem) { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information //ToDo : validation ORM.items.Add(newItem); ORM.SaveChanges(); //sync with the database return(RedirectToAction("Index")); }
public ActionResult DeleteItem(int itemid) { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information //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(); // table needs to have a primary key (use try and catch) return(RedirectToAction("Index")); }
public ActionResult DeleteItem(int itemid) //update { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //for loop to find the id //the Find method is used to find obj by using the primary key item ItemToDelete = ORM.items.Find(itemid); //create new item to find the item you want to delete based on the primary key //remove ORM.items.Remove(ItemToDelete); //remove that obj -- ItemToDelete //save changes on db ORM.SaveChanges(); //ToDo: use try and catch to give an exception return(RedirectToAction("Index")); //return to view with the item list and removed }
public ActionResult SaveChanges(item UpdatedItem) { gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information //find the old record item OldRecord = ORM.items.Find(UpdatedItem.itemid); //ToDo check for null 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")); }