Пример #1
0
        public ActionResult Index(string query = null)
        {
            var upcomingGigs = _context.Gigs
                               .Include(g => g.Artist)
                               .Include(g => g.Genre)
                               .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);

            if (!String.IsNullOrWhiteSpace(query))
            {
                upcomingGigs = upcomingGigs
                               .Where(g =>
                                      g.Artist.Name.Contains(query) ||
                                      g.Genre.Name.Contains(query) ||
                                      g.Venue.Contains(query));
            }

            var userId      = User.Identity.GetUserId();
            var attendances = _attendanceRepositry.GetFutureAttendences(userId)
                              .ToLookup(a => a.GigId);

            var viewModel = new GigsViewModel
            {
                UpcomingGigs = upcomingGigs,
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Upcoming Gigs",
                SearchTerm   = query,
                Attendances  = attendances
            };

            return(View("Gigs", viewModel));
        }