public ActionResult Details(Guid? id)
        {
            if (id == null)
            {
                return new FileNotFoundResult { Message = "No Dinner found due to invalid dinner id" };
            }

            using (var s = db.CreateUnitOfWork())
            {
                HostDinnersQueryContext qryCtx = new HostDinnersQueryContext(s);

                HostDinner hostDinner = qryCtx.GetHostDinnerBy(id.Value);

                if (hostDinner == null)
                {
                    return new FileNotFoundResult { Message = "No Dinner found for that id" };
                }

                return View(hostDinner);
            }
        }
示例#2
0
        public ActionResult GetMostPopularDinners(int? limit)
        {
            using (var s = db.CreateUnitOfWork())
            {
                //var dinners = dinnerRepository.FindUpcomingDinners();

                // Default the limit to 40, if not supplied.
                if (!limit.HasValue)
                    limit = 40;

                //var mostPopularDinners = from dinner in dinners
                //                         orderby dinner.RSVPs.Count descending
                //                         select dinner;

                HostDinnersQueryContext qryCtx = new HostDinnersQueryContext(s);
                var mostPopularDinners = from dinner in qryCtx.FindUpcomingDinners()
                            orderby dinner.RVSPs.Count descending
                            select dinner;

                var jsonDinners =
                    mostPopularDinners.Take(limit.Value).AsEnumerable()
                    .Select(item => JsonDinnerFromDinner(item));

                return Json(jsonDinners.ToList());
            }
        }
        public ActionResult WebSlicePopular()
        {
            ViewData["Title"] = "Popular Nerd Dinners";
            using (var s = db.CreateUnitOfWork())
            {
                HostDinnersQueryContext qryCtx = new HostDinnersQueryContext(s);
                var model = from dinner in qryCtx.FindUpcomingDinners()
                            orderby dinner.RVSPs.Count descending
                            select dinner;

                return View("WebSlice", model.ToList().Take(5));
            }
        }