Exemplo n.º 1
0
        //
        // GET: /Admin/
        public ActionResult Index()
        {
            using (IDocumentSession session = MvcApplication.DB.OpenSession())
            {
                var dinners = session.Query<Dinner>()
                    .OrderBy(d => d.Provider)
                    .ThenBy(d => d.Name)
                    .ToList()
                    .Select(d => new DinnerAvailability { Dinner = d, IsAvailable = d.AvailableByDefault });
                var salads = session.Query<Salad>()
                    .OrderBy(d => d.Provider)
                    .ThenBy(d => d.Name)
                    .ToList()
                    .Select(s => new SaladAvailability { Salad = s, IsAvailable = false });

                var viewModel = new AdminViewModel
                {
                    Dinners = dinners,
                    Salads = salads,
                };

                return View(viewModel);
            }
        }
Exemplo n.º 2
0
        //
        // GET: /Admin/StartBooking
        public ActionResult StartBooking(AdminViewModel model)
        {
            using (IDocumentSession session = MvcApplication.DB.OpenSession())
            {
                var dinners = from d in session.Query<Dinner>().ToList()
                              join dd in model.Dinners on d.Id equals dd.Dinner.Id
                              where dd.IsAvailable == true
                              orderby d.Name
                              select d;

                var salads = from s in session.Query<Salad>().ToList()
                              join ss in model.Salads on s.Id equals ss.Salad.Id
                              where ss.IsAvailable == true
                              orderby s.Name
                              select s;

                var menu = new Menu
                {
                    Date = DateTime.UtcNow,
                    Dinners = dinners,
                    Salads = salads
                };

                session.Store(menu);
                session.SaveChanges();
            }

            return RedirectToAction("Index", "Home");
        }