public ActionResult AddInventory(Item newItem) { if (ModelState.IsValid) { CoffeeDBEntities3 ORM = new CoffeeDBEntities3(); List <Item> items = new List <Item>(); items = (from i in ORM.Items where i.ProductID == newItem.ProductID select i).ToList(); if (items.Count == 0) { ORM.Items.Add(newItem); ORM.SaveChanges(); return(RedirectToAction("AdminList")); } else { ViewBag.ProductName = newItem.ProductID; return(View()); } } else { return(View("AddInventory")); } }
public ActionResult AdminList() { CoffeeDBEntities3 ORM = new CoffeeDBEntities3(); List <Item> OutputList = ORM.Items.ToList(); ViewBag.OutputList = OutputList; return(View()); }
public ActionResult DeleteItem(string ProductID) { CoffeeDBEntities3 ORM = new CoffeeDBEntities3(); Item deleteItem = ORM.Items.Find(ProductID); if (deleteItem != null) { ORM.Items.Remove(deleteItem); ORM.SaveChanges(); } return(RedirectToAction("AdminList")); }
public ActionResult UpdateInventory(string ProductID) { CoffeeDBEntities3 ORM = new CoffeeDBEntities3(); Item RecordToBeUpdated = ORM.Items.Find(ProductID); if (RecordToBeUpdated != null) { ViewBag.RecordToBeUpdated = RecordToBeUpdated; return(View("UpdateInventory")); } else { return(RedirectToAction("AdminList")); } }
public ActionResult SaveUpdatedItem(Item RecordToBeUpdated) { //Todo: validation and exception Handling //1.Find the original record CoffeeDBEntities3 ORM = new CoffeeDBEntities3(); Item temp = ORM.Items.Find(RecordToBeUpdated.ProductID); //2.Do the update on that record, then save to the database temp.Name = RecordToBeUpdated.Name; temp.Type = RecordToBeUpdated.Type; temp.Quantity = RecordToBeUpdated.Quantity; temp.Price = RecordToBeUpdated.Price; ORM.Entry(temp).State = System.Data.Entity.EntityState.Modified; ORM.SaveChanges();//saves to DB //3.Load all customer records return(RedirectToAction("AdminList")); }