Beispiel #1
0
        public ActionResult Index()
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            ViewBag.Items = CoffeeORM.Items.ToList();

            return(View());
        }
Beispiel #2
0
        public ActionResult SearchItemByName(string Name)
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            //Lambda function for searching
            ViewBag.Items = CoffeeORM.Items.Where(x => x.Name.ToLower().Contains(Name.ToLower())).ToList();

            return(View("Index"));
        }
Beispiel #3
0
        public ActionResult SaveNewItem(Item newItem)
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            //NEEDS VALIDATION

            CoffeeORM.Items.Add(newItem);

            CoffeeORM.SaveChanges(); // syncs with the DB

            return(RedirectToAction("Index"));
        }
Beispiel #4
0
        public ActionResult DeleteItem(int itemID)
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            //for loop to find the id
            //find is a mtehod that finds objects using PrimaryKey
            Item ItemToDelete = CoffeeORM.Items.Find(itemID);

            //remove
            CoffeeORM.Items.Remove(ItemToDelete);

            CoffeeORM.SaveChanges();//NEEDS TRY/CATCH

            return(RedirectToAction("Index"));
        }
Beispiel #5
0
        public ActionResult ItemDetails(int itemID)
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            //find item
            Item ItemToEdit = CoffeeORM.Items.Find(itemID);

            if (ItemToEdit == null)
            {
                return(RedirectToAction("Index"));
            }

            //send back to view
            ViewBag.ItemToEdit = ItemToEdit;

            return(View());
        }
Beispiel #6
0
        public ActionResult SaveChanges(Item UpdatedItem)
        {
            CoffeEntities CoffeeORM = new CoffeEntities();

            Item OldRecord = CoffeeORM.Items.Find(UpdatedItem.ItemID);

            //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;

            //Modifies record (original vs current)
            CoffeeORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified;

            CoffeeORM.SaveChanges();

            return(RedirectToAction("Index"));
        }