예제 #1
0
 public ActionResult Login(User u)
 {
     // this action is for handle post (login)
     if (ModelState.IsValid) // this is check validity
     {
         using (Db2Entities dc = new Db2Entities())
         {
             var v = dc.Users.Where(a => a.Username.Equals(u.Username) && a.Password.Equals(u.Password)).FirstOrDefault();
             if (v != null)
             {
                 Session["LogedUserID"]       = v.UserId.ToString();
                 Session["LogedUserFullname"] = v.FullName.ToString();
                 return(RedirectToAction("AfterLogin"));
             }
         }
     }
     return(View(u));
 }
예제 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            drink drink = db.drinks.Find(id);

            using (Db2Entities dbContext = new Db2Entities())
            {
                order order = dbContext.orders.SingleOrDefault(x => x.IdDrink == drink.IdDrink);

                if (order != null)
                {
                    return(RedirectToAction("OrderError"));
                }
                else
                {
                    db.drinks.Remove(drink);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
        }
예제 #3
0
        public ActionResult AcceptConfirmed(int id)
        {
            order order = db.orders.Find(id);

            using (Db2Entities dbContext = new Db2Entities())
            {
                drink drink = dbContext.drinks.SingleOrDefault(x => x.IdDrink == order.IdDrink);

                if (drink.Amount >= order.Amount)
                {
                    drink.Amount = drink.Amount - order.Amount;
                    dbContext.SaveChanges();
                    db.orders.Remove(order);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("StockError"));
                }
            }
        }