예제 #1
0
        public Dictionary <string, long> GetAllGenres()
        {
            Dictionary <string, long> mappingNameIdGenres = new Dictionary <string, long>();
            string urlParameters = $"{GenresMoviesService}?api_key={ApiKey}";

            Genres allGenres = APICallHelper.RunAsync <Genres>(BaseUrl, urlParameters).GetAwaiter().GetResult();

            mappingNameIdGenres = allGenres.GenresList.ToDictionary(g => g.Name, g => g.Id);

            return(mappingNameIdGenres);
        }
예제 #2
0
        private List <string> GetMovies(int numOfMovies, string popularityOrder, List <long> filteredGenres)
        {
            int           page           = 1;
            List <string> selectedMovies = new List <string>();

            while (selectedMovies.Count < numOfMovies)
            {
                string           urlParams = GetUrlParameters(popularityOrder, page, filteredGenres);
                DiscoveredMovies movies    = APICallHelper.RunAsync <DiscoveredMovies>(BaseUrl, urlParams.ToString()).GetAwaiter().GetResult();
                if (movies.TotalResults < numOfMovies)
                {
                    throw new Exception("There aren't enough movies in the database.");
                }

                selectedMovies.AddRange(movies.Results.Select(x => x.Title));
                page++;
            }

            return(selectedMovies.Take(numOfMovies).ToList());
        }