public async Task <int> LoadLkus() { Bpr.Beep1of2(); var sw = Stopwatch.StartNew(); int genresCount = await Task.Run(() => { _db.LkuGenres.Load(); return(_db.LkuGenres.Local.Count()); }); Genres.ClearAddRange(_db.LkuGenres.Local); if (Genres.Count() > 0) { CurGenre = _db.LkuGenres.First(r => r.Name == "All"); } TopLefttInfo = $"{Genres.Count()} genres loaded in {.001 * sw.ElapsedMilliseconds:N1} sec. "; var ttlMU = await LoadList(); Bpr.Beep2of2(); return(genresCount); }
/// <summary> /// Gets the search results for display on the page /// </summary> public void OnGet(double?IMDBMin, double?IMDBMax, double?RottenMin, double?RottenMax) { this.IMDBMin = IMDBMin; this.IMDBMax = IMDBMax; this.RottenMin = RottenMin; this.RottenMax = RottenMax; SearchTerms = Request.Query["SearchTerms"]; MPAARatings = Request.Query["MPAARatings"]; Genres = Request.Query["Genres"]; /* * Movies = MovieDatabase.Search(SearchTerms); * Movies = MovieDatabase.FilterByMPAARating(Movies, MPAARatings); * Movies = MovieDatabase.FilterByGenre(Movies, Genres); * Movies = MovieDatabase.FilterByIMDBRating(Movies, IMDBMin, IMDBMax); * Movies = MovieDatabase.FilterByRottenRating(Movies, RottenMin, RottenMax); */ Movies = MovieDatabase.All; if (SearchTerms != null) { Movies = Movies.Where(movie => movie.Title != null && movie.Title.Contains(SearchTerms, StringComparison.CurrentCultureIgnoreCase) ); // Movies = from movie in Movies // where movie.Title != null && movie.Title.Contains(SearchTerms, StringComparison.CurrentCultureIgnoreCase) // select movie; } if (MPAARatings != null && MPAARatings.Length != 0) { Movies = Movies.Where(movie => movie.MPAARating != null && MPAARatings.Contains(movie.MPAARating) ); } if (Genres != null && Genres.Count() != 0) { Movies = Movies.Where(movie => movie.MajorGenre != null && Genres.Contains(movie.MajorGenre)); } if (IMDBMin != null || IMDBMax != null) { if (IMDBMin == null) { Movies = Movies.Where(movie => movie.IMDBRating <= IMDBMax ); } else if (IMDBMax == null) { Movies = Movies.Where(movie => movie.IMDBRating >= IMDBMin ); } else { Movies = Movies.Where(movie => movie.IMDBRating >= IMDBMin && movie.IMDBRating <= IMDBMax ); } } if (RottenMin != null || RottenMax != null) { if (RottenMin == null) { Movies = Movies.Where(movie => movie.RottenTomatoesRating <= RottenMax ); } else if (RottenMax == null) { Movies = Movies.Where(movie => movie.RottenTomatoesRating >= RottenMin ); } else { Movies = Movies.Where(movie => movie.RottenTomatoesRating >= RottenMin && movie.RottenTomatoesRating <= RottenMax ); } } }
/// <summary> /// Posts the search results for display on the page /// </summary> /// <param name="IMDBMin">The minimum IMDB Rating</param> /// <param name="IMDBMax">The maximum IMDB Rating</param> /// <param name="RottenMin">The minimum Rotten Tomatoes Rating</param> /// <param name="RottenMax">The maximum Rotten Tomatoes Rating</param> public void OnPost() { /* * Movies = MovieDatabase.Search(SearchTerms); * Movies = MovieDatabase.FilterByMPAARating(Movies, MPAARatings); * Movies = MovieDatabase.FilterByGenre(Movies, Genres); * Movies = MovieDatabase.FilterByIMDBRating(Movies, IMDBMin, IMDBMax); * Movies = MovieDatabase.FilterByRottenTomatoesRating(Movies, RottenMin, RottenMax); */ Movies = MovieDatabase.All; // Search movie titles for the SearchTerms if (SearchTerms != null) { Movies = Movies.Where(movie => movie.Title != null && movie.Title.Contains(SearchTerms, StringComparison.CurrentCultureIgnoreCase) ); } // Filter by MPAA Ratings if (MPAARatings != null && MPAARatings.Length != 0) { Movies = Movies.Where(movie => movie.MPAARating != null && MPAARatings.Contains(movie.MPAARating) ); } // Filter by Genre if (Genres != null && Genres.Count() != 0) { Movies = Movies.Where(movie => movie.MajorGenre != null && Genres.Contains(movie.MajorGenre) ); } // Filter by IMBD Rating if (IMDBMax != null || IMDBMin != null) { // Min is null if (IMDBMin == null) { Movies = Movies.Where(movie => movie.IMDBRating <= IMDBMax ); } // Max is null if (IMDBMax == null) { Movies = Movies.Where(movie => movie.IMDBRating >= IMDBMin ); } // Both are specified if (IMDBMax != null && IMDBMin != null) { Movies = Movies.Where(movie => movie.IMDBRating >= IMDBMin && movie.IMDBRating <= IMDBMax ); } } // Filter by RottenTomatoes Rating if (RottenMax != null || RottenMin != null) { // Min is null if (RottenMin == null) { Movies = Movies.Where(movie => movie.RottenTomatoesRating <= RottenMax ); } // Max is null if (RottenMax == null) { Movies = Movies.Where(movie => movie.RottenTomatoesRating >= RottenMin ); } // Both are specified if (RottenMax != null && RottenMin != null) { Movies = Movies.Where(movie => movie.RottenTomatoesRating >= RottenMin && movie.RottenTomatoesRating <= RottenMax ); } } }