Beispiel #1
0
        public ActionResult Admin()
        {
            CoffeeShopDB itemDatabase = new CoffeeShopDB();

            ViewBag.AllItems = itemDatabase.Items.ToList <Item>();
            return(View());
        }
 public ActionResult Index()
 {
     CoffeeShopDB ORM = new CoffeeShopDB();
     List<user> users = new List<user>();
     users = ORM.users.ToList();
     user activeUser = users.ElementAt(users.Count-1);
     ViewBag.ActiveUser = activeUser;
     ViewBag.Items = ORM.item.ToList();
     return View();
 }
Beispiel #3
0
        public ActionResult Edit(Item findItem)
        {
            CoffeeShopDB itemDatabase = new CoffeeShopDB();

            var item = itemDatabase.Items.Where(x => x.ItemName == findItem.ItemName);


            //itemDatabase.Find(id);
            //db.ColorDBs.Remove(colorDB);
            //db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult SaveUser(user newUser)
 {
     CoffeeShopDB ORM = new CoffeeShopDB();
     // TODO: Validation
     if(newUser.firstname != null && newUser.lastname != null && newUser.email != null && newUser.password != null)
     {
         ORM.users.Add(newUser);
         ORM.SaveChanges();
     }
     else
     {
         return RedirectToAction("RegFail");
     }
     return RedirectToAction("Index");
 }
Beispiel #5
0
        public ActionResult Reg(User newUser)
        {
            if (ModelState.IsValid)
            {
                // ToDo: Send the data to the DB

                CoffeeShopDB userDatabase = new CoffeeShopDB();
                userDatabase.Users.Add(newUser);
                userDatabase.SaveChanges();


                ViewBag.ConfMessage = "Thanks " + newUser.fName;

                return(View("Successful"));
            }

            else
            {
                return(View("Error"));
            }
        }
Beispiel #6
0
        //add works by passing in the allitems viewbag and running a try catch to get more details on expections
        public ActionResult Add(Item newItem)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CoffeeShopDB itemDatabase = new CoffeeShopDB();


                    var searchDup = itemDatabase.Items.Where(x => x.ItemName == newItem.ItemName).SingleOrDefault();

                    if (searchDup == null)
                    {
                        itemDatabase.Items.Add(newItem);
                        itemDatabase.SaveChanges();

                        ViewBag.AllItems = itemDatabase.Items.ToList <Item>();
                        return(View("Admin"));
                    }
                    else
                    {
                        ViewBag.WhereError = "Item Already in database";
                        return(View("Error"));
                    }
                }

                else
                {
                    ViewBag.WhereError = "Model State Not Vaild";
                    return(View("Error"));
                }
            }
            catch (Exception)
            {
                ViewBag.WhereError = "Exception Error in Add Item";
                return(View("Error"));
            }
        }