private List <MovieDTO> OrderMovies(List <MovieDTO> movies) { try { var users = UsersManagementIntegration.GetUsers().Users; foreach (var movie in movies) { foreach (var user in users) { var movieWithSameId = user.Movies.Watched.Where(x => x != null && x.Id == movie.Id).FirstOrDefault(); if (movieWithSameId != null && movieWithSameId.Rate != null) { movie.GimmeUsersAverage = movieWithSameId.Rate.GetValueOrDefault(); } } } movies = movies.OrderByDescending(x => x.GimmeUsersAverage).ToList(); return(movies); } catch (Exception) { return(movies); } }
public List <MovieDTO> ProccessSuggestionRequest(SuggestionRequest req) { req = PrepareSuggestionRequest(req); var genresIds = ProccessGenresByText(req.Audio); var user = UsersManagementIntegration.GetUserByEmail(req.UserEmail); var movies = new List <MovieDTO>(); var page = 1; var quantMovies = 20; while (movies.Count < quantMovies) { var moviesResult = TheMovieDbIntegration.GetMovies(genresIds, page, "true", "false").Results; if (moviesResult.Count == 0) { continue; } int difference = quantMovies - movies.Count; moviesResult = moviesResult.Take(difference).ToList(); movies.AddRange(FilterMoviesListByUser(moviesResult, user)); page++; } movies = movies.OrderByDescending(x => x.Popularity).ToList(); movies = OrderMovies(movies); return(movies); }
public MovieDTO ProccessImFeelingLuckyRequest(SuggestionRequest req) { _tempIntegration.DeleteOld(); var genresIds = ProccessGenresByTime(req.Time); var user = UsersManagementIntegration.GetUserByEmail(req.UserEmail); var movie = new MovieDTO(); var page = 1; while (movie.Id == 0) { var moviesResult = TheMovieDbIntegration.GetMovies(genresIds, page, "true", "false").Results; if (moviesResult.Count == 0) { genresIds = ""; continue; } foreach (var movieResult in moviesResult) { var moviesList = new List <MovieDTO> { movieResult }; movie = FilterMoviesListByUser(moviesList, user, true).FirstOrDefault(); if (movie != null) { break; } } page++; } _tempIntegration.InsertOne(new TempMovieDTO() { MovieId = movie.Id, UserEmail = user.Email, CreatedOn = DateTime.Now }); return(movie); }