public ActionResult Create([Bind(Include = "Name,Description,Quantity,Price")] Item item) { if (ModelState.IsValid) { db.Items.Add(item); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(item)); }
public ActionResult EditItem(Item updateItem) { { CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2(); Item OldItem = ORM.Items.Find(updateItem.Name); if (OldItem != null && ModelState.IsValid) { OldItem.Name = updateItem.Name; OldItem.Description = updateItem.Description; OldItem.Quantity = updateItem.Quantity; OldItem.Price = updateItem.Price; ORM.Entry(OldItem).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges(); ViewBag.Message = "Updates have been completed!"; return(View()); } else { ViewBag.ErrorMessage = "Something went wrong! Please try again!"; return(View("Error")); } } }
public ActionResult DeleteItem(string name) { CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2(); Item ItemToDelete = ORM.Items.Find(name); ORM.Items.Remove(ItemToDelete); ORM.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddNewItem(Item newItem) { if (ModelState.IsValid) { CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2(); ORM.Items.Add(newItem); ORM.SaveChanges(); return(RedirectToAction("Admin")); } else { return(View("Error")); } }
public ActionResult AddNewUser(User newUser) { CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2(); if (ModelState.IsValid) { ORM.Users.Add(newUser); ORM.SaveChanges(); ViewBag.Message = $"Welcome {newUser.First_Name}!"; return(View("Confirm")); } else { return(View("Error")); } }
public ActionResult DeleteItem(string Name) { CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2(); Item Found = ORM.Items.Find(Name); if (Found != null) { ORM.Items.Remove(Found); ORM.SaveChanges(); return(View()); } else { return(View("Error")); } }