/// <summary> /// Gets recently requested movies /// </summary> /// <returns></returns> public async Task <IEnumerable <SearchMovieViewModel> > RecentlyRequestedMovies(int currentlyLoaded, int toLoad, CancellationToken cancellationToken) { var langCode = await DefaultLanguageCode(null); var results = new List <MovieResponseDto>(); var requestResult = await Cache.GetOrAdd(nameof(RecentlyRequestedMovies) + "Requests" + toLoad + langCode, async() => { return(await _movieRequestEngine.GetRequests(toLoad, currentlyLoaded, new Models.UI.OrderFilterModel { OrderType = OrderType.RequestedDateDesc })); }, DateTime.Now.AddMinutes(15), cancellationToken); var movieDBResults = await Cache.GetOrAdd(nameof(RecentlyRequestedMovies) + toLoad + langCode, async() => { var responses = new List <MovieResponseDto>(); foreach (var movie in requestResult.Collection) { responses.Add(await MovieApi.GetMovieInformation(movie.TheMovieDbId)); } return(responses); }, DateTime.Now.AddHours(12), cancellationToken); results.AddRange(movieDBResults); return(await TransformMovieResultsToResponse(results)); }
public async Task <List <VoteViewModel> > GetMovieViewModel() { var vm = new List <VoteViewModel>(); var movieRequests = await _movieRequestEngine.GetRequests(); var tvRequestsTask = _tvRequestEngine.GetRequests(); var musicRequestsTask = _musicRequestEngine.GetRequests(); var user = await GetUser(); foreach (var r in movieRequests) { if (r.Available || r.Approved || (r.Denied ?? false)) { continue; } // Make model var votes = GetVotes(r.Id, RequestType.Movie); var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted); vm.Add(new VoteViewModel { Upvotes = upVotes, Downvotes = downVotes, RequestId = r.Id, RequestType = RequestType.Movie, Title = r.Title, Image = $"https://image.tmdb.org/t/p/w500/{r.PosterPath}", Background = $"https://image.tmdb.org/t/p/w1280{r.Background}", Description = r.Overview, AlreadyVoted = myVote != null, MyVote = myVote?.VoteType ?? VoteType.Downvote }); } foreach (var r in await musicRequestsTask) { if (r.Available || r.Approved || (r.Denied ?? false)) { continue; } // Make model var votes = GetVotes(r.Id, RequestType.Album); var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted); vm.Add(new VoteViewModel { Upvotes = upVotes, Downvotes = downVotes, RequestId = r.Id, RequestType = RequestType.Album, Title = r.Title, Image = r.Cover, Background = r.Cover, Description = r.ArtistName, AlreadyVoted = myVote != null, MyVote = myVote?.VoteType ?? VoteType.Downvote }); } foreach (var r in await tvRequestsTask) { foreach (var childRequests in r.ChildRequests) { var finalsb = new StringBuilder(); if (childRequests.Available || childRequests.Approved || (childRequests.Denied ?? false)) { continue; } var votes = GetVotes(childRequests.Id, RequestType.TvShow); // Make model var upVotes = await votes.Where(x => x.VoteType == VoteType.Upvote).CountAsync(); var downVotes = await votes.Where(x => x.VoteType == VoteType.Downvote).CountAsync(); var myVote = await votes.FirstOrDefaultAsync(x => x.UserId == user.Id && !x.Deleted); foreach (var epInformation in childRequests.SeasonRequests.OrderBy(x => x.SeasonNumber)) { var orderedEpisodes = epInformation.Episodes.OrderBy(x => x.EpisodeNumber).ToList(); var episodeString = NewsletterJob.BuildEpisodeList(orderedEpisodes.Select(x => x.EpisodeNumber)); finalsb.Append($"Season: {epInformation.SeasonNumber} - Episodes: {episodeString}"); finalsb.Append("<br />"); } vm.Add(new VoteViewModel { Upvotes = upVotes, Downvotes = downVotes, RequestId = childRequests.Id, RequestType = RequestType.TvShow, Title = r.Title, Image = r.PosterPath, Background = r.Background, Description = finalsb.ToString(), AlreadyVoted = myVote != null, MyVote = myVote?.VoteType ?? VoteType.Downvote }); } } return(vm); }
public async Task <RequestsViewModel <MovieRequests> > GetRequests(int count, int position, string sort, string sortOrder) { return(await _movieRequestEngine.GetRequests(count, position, sort, sortOrder)); }