Example #1
0
        public string BuildEpisodeListTest(List <int> episodes)
        {
            var emailSettings      = new Mock <ISettingsService <EmailNotificationSettings> >();
            var customziation      = new Mock <ISettingsService <CustomizationSettings> >();
            var newsletterSettings = new Mock <ISettingsService <NewsletterSettings> >();
            var newsletter         = new NewsletterJob(null, null, null, null, null, null, customziation.Object, emailSettings.Object, null, null, newsletterSettings.Object, null);

            var ep = new List <int>();

            foreach (var i in episodes)
            {
                ep.Add(i);
            }
            var result = newsletter.BuildEpisodeList(ep);

            return(result);
        }
Example #2
0
        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);
        }