Esempio n. 1
0
        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"));
            }
        }
Esempio n. 2
0
        public ActionResult AdminList()
        {
            CoffeeDBEntities3 ORM = new CoffeeDBEntities3();

            List <Item> OutputList = ORM.Items.ToList();

            ViewBag.OutputList = OutputList;

            return(View());
        }
Esempio n. 3
0
        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"));
        }
Esempio n. 4
0
        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"));
            }
        }
Esempio n. 5
0
        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"));
        }