// Index has the search term query as null by default. When the user submits a search 
        // then the Index will filter by that search term query, if applicable.
        public ActionResult Index(string query = null)
        {
            // On our index page, we make sure to only display the meetups 
            // that are not cancelled.
            var upcomingMeetups = _context.Meetups
                .Include(m => m.Group)
                .Include(m => m.Category)
                .Where(m => m.DateTime > DateTime.Now && !m.IsCancelled);

            if (!string.IsNullOrWhiteSpace(query))
            {
                // If our search term query is not null, we search through the group's name, 
                // the meetup's category, title and description for that query.
                upcomingMeetups = upcomingMeetups.Where(m =>
                    m.Group.Name.Contains(query) ||
                    m.Category.Name.Contains(query) ||
                    m.Title.Contains(query) ||
                    m.Description.Contains(query));
            }

            var viewModel = new MeetupsViewModel
            {
                UpcomingMeetups = upcomingMeetups,
                ShowActions = User.Identity.IsAuthenticated,
                Heading = "Upcoming Meetups",
                SearchTerm = query
            };

            return View("Meetups", viewModel);
        }
        public ActionResult Attending()
        {
            // This line has to be assigned to a variable as LINQ won't recognize it.
            var userId = User.Identity.GetUserId();
            var meetups = _context.Attendances
                .Where(a => a.AttendeeId == userId)
                .Select(a => a.Meetup)
                .Include(c => c.Category)
                .Include(g => g.Group)
                .ToList();

            var viewModel = new MeetupsViewModel()
            {
                UpcomingMeetups = meetups,
                ShowActions = User.Identity.IsAuthenticated,
                Heading = "Meetups I'm attending"
            };

            return View("Meetups", viewModel);
        }
 public ActionResult Search(MeetupsViewModel viewModel)
 {
     // Searching is done through the search box on the Index page. We'll use HttpPost to submit a query to 
     // the Index action of our HomeController. 
     return RedirectToAction("Index", "Home", new { query = viewModel.SearchTerm });
 }