示例#1
0
        public ActionResult Index()
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            ViewBag.Items = ORM.items.ToList();
            return(View());
        }
示例#2
0
        public ActionResult SaveChanges(item updatedItem) //update
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            //find the old record that you're updating
            item OldRecord = ORM.items.Find(updatedItem.itemid);

            //ToDo: check for null!!!!!!
            //if (OldRecord == null)
            //{
            //    return View("Index");
            //}

            //don't need to update itemid because that stays the same
            OldRecord.name        = updatedItem.name;
            OldRecord.description = updatedItem.description;
            OldRecord.quantity    = updatedItem.quantity;
            OldRecord.price       = updatedItem.price;

            //need to change the state of the record from original to the modified state!!
            ORM.Entry(OldRecord).State = System.Data.Entity.EntityState.Modified;

            ORM.SaveChanges();

            return(RedirectToAction("Index"));
        }
示例#3
0
        public ActionResult SearchItemByName(string name)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information

            ViewBag.Items = ORM.items.Where(x => x.name.ToLower().Contains(name.ToLower())).ToList();

            return(View("Index"));
        }
示例#4
0
        public ActionResult SaveChanges(User newUser)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            ORM.Users.Add(newUser);
            ORM.SaveChanges();
            return(RedirectToActionPermanent("Products"));
        }
示例#5
0
        public ActionResult Index() //create
        {
            //READ part of the CRUD opperation
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            ViewBag.items = ORM.items.ToList();

            return(View());
        }
示例#6
0
        public ActionResult SearchItemByName(string name)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            ViewBag.Items = ORM.items.Where(x => x.name.ToLower().Contains
                                                (name.ToLower())).ToList();

            return(View("Index"));
        }
示例#7
0
        public ActionResult SaveNewItem(item newItem)              //add
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //ORM... needed for anytime you talk to db (found in index)

            // ToDo: data validation!!! if statement
            ORM.items.Add(newItem);            //adding newItem obj to the form serverside
            ORM.SaveChanges();                 //sync with the database and show the changes and what is saved

            return(RedirectToAction("Index")); //bounce back to index to show the list of items we have
        }
示例#8
0
        public ActionResult SaveNewItem(item newItem)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information

            //ToDo : validation

            ORM.items.Add(newItem);
            ORM.SaveChanges(); //sync with the database

            return(RedirectToAction("Index"));
        }
示例#9
0
        public ActionResult ItemDetails(int itemid) //this action will show the data before the update
        {                                           //this action will show the data before the update
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            //find the item
            item ItemToEdit = ORM.items.Find(itemid);

            //sent it back to view
            ViewBag.ItemToEdit = ItemToEdit;
            return(View());
        }
示例#10
0
        public ActionResult ItemDetails(int itemid)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information
            item ItemtoEdit          = ORM.items.Find(itemid);

            if (ItemtoEdit == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.ItemToEdit = ItemtoEdit;
            return(View());
        }
示例#11
0
        public ActionResult DeleteItem(int itemid)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information
            //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(); // table needs to have a primary key (use try and catch)
            return(RedirectToAction("Index"));
        }
示例#12
0
        public ActionResult Register(string email)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information
            User UsertoEdit          = ORM.Users.Find(email);

            if (UsertoEdit == null)
            {
                return(RedirectToAction("Index"));
            }
            ViewBag.UserToEdit = UsertoEdit;
            //ToDo : validation

            return(View());
        }
示例#13
0
        public ActionResult DeleteItem(int itemid) //update
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();
            //for loop to find the id
            //the Find method is used to find obj by using the primary key
            item ItemToDelete = ORM.items.Find(itemid); //create new item to find the item you want to delete based on the primary key

            //remove
            ORM.items.Remove(ItemToDelete);    //remove that obj -- ItemToDelete
            //save changes on db
            ORM.SaveChanges();                 //ToDo: use try and catch to give an exception

            return(RedirectToAction("Index")); //return to view with the item list and removed
        }
示例#14
0
        public ActionResult SaveChanges(item UpdatedItem)
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities(); //need this is every operation that takes in information
            //find the old record
            item OldRecord = ORM.items.Find(UpdatedItem.itemid);

            //ToDo check for null
            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"));
        }
示例#15
0
        public ActionResult NewCustomer() //post
        {
            gccoffeeshopEntities ORM = new gccoffeeshopEntities();

            return(View());
        }