Ejemplo n.º 1
0
        public ActionResult Index(string query = null)
        {
            var upcomingGugs = _context.Gigs
                               .Include(t => t.Artist)
                               .Include(t => t.Genre)
                               .Where(g => g.DateTime > DateTime.Now && !g.IsCanceled);

            if (!string.IsNullOrWhiteSpace(query))
            {
                upcomingGugs = upcomingGugs.Where(g =>
                                                  g.Artist.Name.Contains(query) ||
                                                  g.Genre.Name.Contains(query) ||
                                                  g.Venue.Contains(query)
                                                  );
            }
            var userId = User.Identity.GetUserId();

            var viewModel = new GigsViewModel
            {
                UpcomingGigs = upcomingGugs,
                ShowActions  = User.Identity.IsAuthenticated,
                Heading      = "Upcoming Gigs",
                SearchTerm   = query,
                Attendances  = _attendanceRepository.GetFutereAttendances(userId)
                               .ToLookup(a => a.GigId)
            };

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