Beispiel #1
0
        public ActionResult Order1(OrderingViewModel model)
        {
            using (var session = MvcApplication.DB.OpenSession())
            {
                model.Menu = GetMenu(session);
                model.Order.Person = User.Identity.Name;
                model.TimeLimit = model.Menu.Date.AddMinutes(TimeLimit);

                ModelState.Clear();
                if (TryValidateModel(model))
                {
                    if (!model.Menu.Dinners.Single(d => d.Id == model.Order.Dinner.DinnerId).HasPotatoes)
                    {
                        model.Order.Dinner.Potatoes = Potatoes.None;
                    }

                    session.Store(model.Order);
                    session.SaveChanges();

                    Session["Message"] = " Order placed.";

                    return RedirectToAction("index");
                }
            }

            return View(model);
        }
Beispiel #2
0
        public ActionResult Order2(OrderingViewModel model)
        {
            using (var session = MvcApplication.DB.OpenSession())
            {
                model.Menu = GetMenu(session);
                var order = session.Load<Order>("orders/" + model.Order.Id);
                order.SaladIds[1] = model.Order.SaladIds[1];
                model.Order = order;

                if (CountMissingSalads(session, order.MenuId) == 0)
                {
                    Session["Message"] = "Someone was faster than you.";
                    return RedirectToAction("index");
                }

                ModelState.Clear();
                if (TryValidateModel(model))
                {
                    session.Store(order);
                    session.SaveChanges();
                }
            }

            return RedirectToAction("index");
        }
Beispiel #3
0
        public ActionResult Index()
        {
            using (var session = MvcApplication.DB.OpenSession())
            {
                var menu = GetMenu(session);
                if (menu == null)
                {
                    return RedirectToAction("index", "admin");
                }

                string menuId = "menus/" + menu.Id.ToString();
                DateTime timeLimit = DateTime.UtcNow.AddMinutes(-TimeLimit);

                var order = GetOrCreateOrder(session, menuId);

                var viewModel = new OrderingViewModel
                {
                    Menu = menu,
                    Order = order,
                    TimeLimit = menu.Date.AddMinutes(TimeLimit)
                };

                if (menu.Date > timeLimit)
                {
                    return View("order1", viewModel);
                }

                if (CountMissingSalads(session, menuId) > 0)
                {
                    return View("order2", viewModel);
                }

                return View();
            }
        }