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 int Create50MovieModelsFromUnogsDBEntries(int offset, bool loadFromAPI)
        {
            var unogs           = MongoDBRepo.GetAll <UnogsModel>("unogs").Skip(offset).Take(50);
            var imdbIds         = unogs.Select(x => x.Imdbid);
            var movies          = new List <MovieModel>();
            var unogsWithNoMeta = new List <string>();
            var totalApiCalls   = 0;

            foreach (var unog in unogs)
            {
                // first check metaCahce
                var dojo = MongoDBRepo.GetById <DojoModel>("dojocache", unog.Imdbid);
                if (dojo != null)
                {
                    var movie = new MovieModel(unog, dojo);
                    movies.Add(movie);
                }
                else
                // Add to a list to fetch from dojo api
                {
                    unogsWithNoMeta.Add(unog.Imdbid);
                }
            }
            // If it's an new batch of movies with no meta, get from the dojo api
            if (unogsWithNoMeta.Count() > 49 && loadFromAPI)
            {
                LoadDojo(unogsWithNoMeta);
                totalApiCalls++;
            }
            else
            {
                Debug.Write("did not fetch data for following id's : ");
                foreach (var id in unogsWithNoMeta)
                {
                    Debug.Write(id + ", ");
                }
                Debug.WriteLine(" | Total: " + unogsWithNoMeta.Count());
            }

            MongoDBRepo.InsertMany <MovieModel>("movies", movies);
            return(totalApiCalls);
        }
        public List <UserMovieModel> CreateMovieViews(int userId, FilterModel filters, int resultLimit, int offset)
        {
            var ratingFilter = Builders <MovieModel> .Filter.Gt(x => x.Rating, filters.MinRating);

            var runtimeFilter = Builders <MovieModel> .Filter.Lt(x => x.RunTime, filters.MaxRuntime);

            var filter = Builders <MovieModel> .Filter.And(ratingFilter, runtimeFilter);

            if (filters.Keyword != null && filters.Keyword.Length > 0)
            {
                var keyWordFilter = Builders <MovieModel> .Filter.Regex(x => x.Title, new BsonRegularExpression($".*{filters.Keyword}.*", "i"));

                filter = Builders <MovieModel> .Filter.And(filter, keyWordFilter);
            }

            if (filters.Genres.Count() > 0)
            {
                var genreFilter = Builders <MovieModel> .Filter.AnyIn(x => x.Genres, filters.Genres.Select(g => g.ToString()));

                filter = Builders <MovieModel> .Filter.And(filter, genreFilter);
            }
            var movies = _MongoDBRepo.Query("movies", filter);

            var movieViews = new List <UserMovieModel>();

            foreach (var movie in movies.Skip(offset).Take(resultLimit))
            {
                var userdata = _MongoDBRepo.GetById <UserMoviedataModel>("usermoviedata", movie.ImdbId);
                if (userdata != null)
                {
                    var movieview = new UserMovieModel(movie, userdata);
                    movieViews.Add(movieview);
                }
                else
                {
                    var movieview = new UserMovieModel(movie);
                    movieViews.Add(movieview);
                }
            }
            return(movieViews);
        }
 public UserMoviedataModel GetMovieData(string movieId, int userId) =>
 _MongoDBRepo.GetById <UserMoviedataModel>("usermoviedata", movieId);