Exemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Name,Description,Quantity,Price")] Item item)
        {
            if (ModelState.IsValid)
            {
                db.Items.Add(item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
Exemplo n.º 2
0
        public ActionResult EditItem(Item updateItem)
        {
            {
                CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();

                Item OldItem = ORM.Items.Find(updateItem.Name);

                if (OldItem != null && ModelState.IsValid)
                {
                    OldItem.Name        = updateItem.Name;
                    OldItem.Description = updateItem.Description;
                    OldItem.Quantity    = updateItem.Quantity;
                    OldItem.Price       = updateItem.Price;


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

                    ORM.SaveChanges();

                    ViewBag.Message = "Updates have been completed!";
                    return(View());
                }
                else
                {
                    ViewBag.ErrorMessage = "Something went wrong! Please try again!";
                    return(View("Error"));
                }
            }
        }
Exemplo n.º 3
0
        public ActionResult DeleteItem(string name)
        {
            CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();

            Item ItemToDelete = ORM.Items.Find(name);

            ORM.Items.Remove(ItemToDelete);


            ORM.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public ActionResult AddNewItem(Item newItem)
        {
            if (ModelState.IsValid)
            {
                CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();
                ORM.Items.Add(newItem);

                ORM.SaveChanges();

                return(RedirectToAction("Admin"));
            }

            else
            {
                return(View("Error"));
            }
        }
Exemplo n.º 5
0
        public ActionResult AddNewUser(User newUser)
        {
            CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();

            if (ModelState.IsValid)
            {
                ORM.Users.Add(newUser);
                ORM.SaveChanges();

                ViewBag.Message = $"Welcome {newUser.First_Name}!";
                return(View("Confirm"));
            }

            else
            {
                return(View("Error"));
            }
        }
Exemplo n.º 6
0
        public ActionResult DeleteItem(string Name)
        {
            CoffeeShopDBEntities2 ORM = new CoffeeShopDBEntities2();
            Item Found = ORM.Items.Find(Name);


            if (Found != null)
            {
                ORM.Items.Remove(Found);
                ORM.SaveChanges();

                return(View());
            }

            else
            {
                return(View("Error"));
            }
        }