public List <MovieviewModel> CreateMovieViews(int userId, FilterModel filters, int resultLimit, int offset)
        {
            var movies     = _MongoDBRepo.GetAll <MovieModel>("movies");
            var movieViews = new List <MovieviewModel>();

            if (filters != null)
            {
                movies = movies.Where(m => m.Movie.Rating > filters.MinRating && m.Movie.RunTime < filters.MaxRuntime).ToList();

                if (filters.Keyword != null && filters.Keyword.Length > 0)
                {
                    movies = movies.Where(m => m.Movie.Title.Contains(filters.Keyword)).ToList();
                }
                if (filters.Genres.Count() > 0)
                {
                    movies = movies.Where(m => m.Metadata.Genres.Intersect <string>(filters.Genres.Select(g => g.ToString())).Any()).ToList();
                }
            }

            foreach (var movie in movies.Skip(offset).Take(resultLimit))
            {
                var userdata = _MongoDBRepo.GetById <UserMoviedataModel>("userdata", movie.ImdbId);
                if (userdata != null)
                {
                    var movieview = new MovieviewModel(movie, userdata);
                    movieViews.Add(movieview);
                }
                else
                {
                    var movieview = new MovieviewModel(movie);
                    movieViews.Add(movieview);
                }
            }
            return(movieViews);
        }
        public void LoadUnogs(int callLimit, int startOffset = 0)
        {
            var totalNoOfResultsFromQuery = 5000;
            var totalFetched = 0;
            var calls        = 0;

            while (totalFetched < totalNoOfResultsFromQuery && calls < callLimit)
            {
                calls++;
                var movies = new List <UnogsModel>();
                var offset = startOffset + totalFetched;

                var movieJson = UnogsRepo.GetMovieJson(offset);

                if (movieJson != null)
                {
                    var movieResults = UnogsRepo.ConvertJsonToMovieResult(movieJson);

                    // store current value of array
                    var lastCountOfMoviesDB = MongoDBRepo.GetAll <UnogsModel>("unogs").Count();

                    // add new results to old results
                    if (movieResults.Movies != null)
                    {
                        movies.AddRange(movieResults.Movies);
                    }

                    totalFetched += movies.Count();

                    Console.WriteLine("saving movies...");
                    SaveUnogsToDB(movies);

                    Console.WriteLine(
                        $"call:{calls}, fetched {movieResults.MoviesFetched} movies," +
                        $" called with offset {offset}, " +
                        $"movie collection changed from {lastCountOfMoviesDB} " +
                        $"to {MongoDBRepo.GetAll<UnogsModel>("unogs").Count()} ");
                    Console.WriteLine("----");
                }
            }
        }