示例#1
0
        public ActionResult IncMeal(int?orderID, int?mealID)
        {
            if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "chef")
            {
                List <DAL.OrderProduct> orderProducts = opRepo.GetCurrent();
                bool found = false;
                foreach (DAL.OrderProduct op in orderProducts)
                {
                    if (op.OrderID == orderID)
                    {
                        if (op.MealID == mealID)
                        {
                            op.Quantity = op.Quantity + 1;
                            opRepo.Update(op);
                            found = true;
                        }
                    }
                }
                if (!found)
                {
                    OrderProduct op = new OrderProduct();
                    op.IsDeleted = false;
                    op.MealID    = mealID;
                    op.OrderID   = orderID;
                    op.Quantity  = 1;
                    opRepo.Add(op);
                }

                oRepo.updatePrice((int)orderID);

                return(RedirectToAction("EditMeals", "Chef", new { i = orderID }));
            }
            return(RedirectToAction("Login", "Home", new { area = "" }));
        }
示例#2
0
        public ActionResult Checkout()
        {
            if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "user")
            {
                if (Session["fromCheckout"] != null && Session["fromCheckout"].ToString() != "yes")
                {
                    return(RedirectToAction("Login", "Home"));
                }


                List <MealModel> cart = (List <MealModel>)Session["CartItems"];

                Order ord = new Order();
                ord.Date      = DateTime.Now;
                ord.IsDeleted = false;


                ord.QRCodePath = genQR();
                ViewBag.QR     = ord.QRCodePath;


                ord.TotalPrice    = 0;
                ord.EstimatedTime = DateTime.Now;
                int delay = 0;
                foreach (MealModel m in cart)
                {
                    ord.TotalPrice += m.Quantity * m.Price;
                    if (m.Quantity > mRepo.GetByID(m.ID).Stock)
                    {
                        delay++;
                    }
                }

                ord.EstimatedTime = DateTime.Now.AddMinutes(delay * 5);
                ord.UserID        = Int32.Parse(Session["UserID"].ToString());
                ord.VoucherID     = null;

                oRepo.Add(ord);

                foreach (MealModel m in cart)
                {
                    OrderProduct op = new OrderProduct();
                    op.IsDeleted = false;
                    op.MealID    = m.ID;
                    op.OrderID   = ord.ID;
                    op.Quantity  = m.Quantity;
                    opRepo.Add(op);
                }

                return(View());
            }
            return(RedirectToAction("Login", "Home", new { area = "" }));
        }