// GET: Shows public async Task <IActionResult> Index(string showGenre, string searchString) { // Use LINQ to get list of genres. IQueryable <string> genreQuery = from s in _context.Show orderby s.Genre select s.Genre; var shows = (IQueryable <Show>) from s in _context.Show orderby s.Title select s; if (!string.IsNullOrEmpty(searchString)) { shows = shows.Where(s => s.Title.Contains(searchString)); } if (!string.IsNullOrEmpty(showGenre)) { shows = shows.Where(x => x.Genre == showGenre); } var showGenreVM = new ShowGenreViewModel { Genres = new SelectList(await genreQuery.Distinct().ToListAsync()), Shows = await shows.ToListAsync() }; return(View(showGenreVM)); }
// GET: Shows public async Task <IActionResult> Index(string searchString, string showGenre, string showRating) { //// using LINQ to get a list of genres IQueryable <string> genreQuery = from m in _context.Show orderby m.Genre select m.Genre; var shows = from m in _context.Show select m; if (!String.IsNullOrEmpty(searchString)) { shows = shows.Where(s => s.Title.Contains(searchString)); } if (!String.IsNullOrEmpty(showGenre)) { shows = shows.Where(z => z.Genre == showGenre); } if (!String.IsNullOrEmpty(showRating)) { shows = shows.Where(y => y.Rating == showRating); } var showGenreVM = new ShowGenreViewModel(); showGenreVM.genres = new SelectList(await genreQuery.Distinct().ToListAsync()); showGenreVM.shows = await shows.ToListAsync(); return(View(showGenreVM)); }