public ActionResult Edit(int?i) { if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "chef") { if (i != null) { Meal m = mRepo.GetByID((int)i); MealModel mm = new MealModel() { Description = m.Description, ID = m.ID, Name = m.Name, PhotoPath = m.PhotoPath, Price = (int)m.Price, Quantity = (int)m.Stock }; return(View(mm)); } } return(RedirectToAction("Login", "Home", new { area = "" })); }
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 = "" })); }
public ActionResult AddToCart(int?id) { if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "user") { if (id != null) { Meal m = mRepo.GetByID((int)id); MealModel meal = new MealModel() { ID = m.ID, Description = m.Description, Name = m.Name, PhotoPath = m.PhotoPath, Quantity = 1, Price = (int)m.Price }; if (Session["CartItems"] == null) { Session["CartItems"] = new List <MealModel>(); } List <MealModel> current_cart = (List <MealModel>)Session["CartItems"]; MealModel current = null; foreach (MealModel mm in current_cart) { if (mm.ID == meal.ID) { current = mm; break; } } if (current != null) { meal.Quantity = current.Quantity + 1; ((List <MealModel>)Session["CartItems"]).Remove(current); } ((List <MealModel>)Session["CartItems"]).Add(meal); List <MealModel> cart = (List <MealModel>)Session["CartItems"]; } return(RedirectToAction("Index", "User")); } return(RedirectToAction("Login", "Home", new { area = "" })); }
public ActionResult Scan(int?id) { if (Session["UserID"] != null && Session["UserType"].ToString().ToLower() == "chef") { if (id == null) { return(RedirectToAction("Index")); } Order ord = oRepo.GetByID((int)id); List <DAL.User> users = uRepo.GetCurrent(); List <DAL.Meal> meals = mRepo.GetCurrent(); List <DAL.OrderProduct> orderProducts = opRepo.GetCurrent(); OrderModel om = new OrderModel(); if (ord.Date != null) { om.Date = (DateTime)ord.Date; } else { om.Date = new DateTime(); } om.EstimatedTime = ord.EstimatedTime; om.ID = ord.ID; om.QRCodePath = ord.QRCodePath; om.TotalPrice = ord.TotalPrice; om.Voucher = null; UserModel um = new UserModel(); if (ord.UserID != null) { var usr = uRepo.GetByID((int)ord.UserID); if (usr.DOB != null) { um.DOB = (DateTime)usr.DOB; } else { um.DOB = new DateTime(); } um.ID = usr.ID; um.Mail = usr.Mail; um.Name = usr.Name; um.NrOrders = usr.NrOrders; um.Type = usr.Type; } om.User = um; List <MealModel> mm = new List <MealModel>(); foreach (DAL.OrderProduct op in orderProducts) { if (op.OrderID == ord.ID) { MealModel mealmodel = new MealModel(); Meal meal = mRepo.GetByID((int)op.MealID); mealmodel.ID = meal.ID; mealmodel.Name = meal.Name; if (op.Quantity == null) { mealmodel.Quantity = 0; } else { mealmodel.Quantity = (int)op.Quantity; } mm.Add(mealmodel); } } om.Meals = mm; Session["ordID"] = id; return(View(om)); } return(RedirectToAction("Login", "Home", new { area = "" })); }