Beispiel #1
0
        public ActionResult SaveChanges(item UpdatedItem)
        {
            lab24Entities ORM = new lab24Entities();

            // find the old record

            item OldRecord = ORM.Items.Find(UpdatedItem.itemID);

            //To Do: 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;

            ORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified;

            ORM.SaveChanges();

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public ActionResult SaveNewItem(item newItem)
        {
            lab24Entities ORM = new lab24Entities();

            //To Do: Validation!

            ORM.Items.Add(newItem);

            ORM.SaveChanges(); // sync with the database
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult DeleteItem(int itemID)
        {
            lab24Entities ORM = new lab24Entities();

            // 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(); // To Do: use try catch

            return(RedirectToAction("Index"));
        }