Example #1
0
        public async Task <IEnumerable <TreeNode <TvRequests, List <ChildRequests> > > > GetRequestsTreeNode(int count, int position)
        {
            var shouldHide = await HideFromOtherUsers();

            List <TvRequests> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = await TvRepository.Get(shouldHide.UserId)
                              .Include(x => x.ChildRequests)
                              .ThenInclude(x => x.SeasonRequests)
                              .ThenInclude(x => x.Episodes)
                              .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
                              .Skip(position).Take(count).ToListAsync();

                FilterChildren(allRequests, shouldHide);
            }
            else
            {
                allRequests = await TvRepository.Get()
                              .Include(x => x.ChildRequests)
                              .ThenInclude(x => x.SeasonRequests)
                              .ThenInclude(x => x.Episodes)
                              .OrderByDescending(x => x.ChildRequests.Max(y => y.RequestedDate))
                              .Skip(position).Take(count).ToListAsync();
            }

            allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
            return(ParseIntoTreeNode(allRequests));
        }
Example #2
0
        public async Task<IEnumerable<TvRequests>> GetRequests(int count, int position)
        {
            var shouldHide = await HideFromOtherUsers();
            List<TvRequests> allRequests;
            if (shouldHide.Hide)
            {
                allRequests = await TvRepository.Get(shouldHide.UserId)
                    .Include(x => x.ChildRequests)
                    .ThenInclude(x => x.SeasonRequests)
                    .ThenInclude(x => x.Episodes)
                    .Skip(position).Take(count).ToListAsync();

                // Filter out children

                FilterChildren(allRequests, shouldHide);
            }
            else
            {
                allRequests = await TvRepository.Get()
                    .Include(x => x.ChildRequests)
                    .ThenInclude(x => x.SeasonRequests)
                    .ThenInclude(x => x.Episodes)
                    .Skip(position).Take(count).ToListAsync();
            }

            return allRequests;
        }
Example #3
0
        public async Task <RequestsViewModel <TvRequests> > GetRequests(int count, int position, OrderFilterModel type)
        {
            var shouldHide = await HideFromOtherUsers();

            List <TvRequests> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = await TvRepository.Get(shouldHide.UserId)
                              .Include(x => x.ChildRequests)
                              .ThenInclude(x => x.SeasonRequests)
                              .ThenInclude(x => x.Episodes)
                              .OrderByDescending(x => x.ChildRequests.Select(y => y.RequestedDate).FirstOrDefault())
                              .Skip(position).Take(count).ToListAsync();

                // Filter out children

                FilterChildren(allRequests, shouldHide);
            }
            else
            {
                allRequests = await TvRepository.Get()
                              .Include(x => x.ChildRequests)
                              .ThenInclude(x => x.SeasonRequests)
                              .ThenInclude(x => x.Episodes)
                              .OrderByDescending(x => x.ChildRequests.Select(y => y.RequestedDate).FirstOrDefault())
                              .Skip(position).Take(count).ToListAsync();
            }
            await CheckForSubscription(shouldHide, allRequests);

            return(new RequestsViewModel <TvRequests>
            {
                Collection = allRequests
            });
        }
Example #4
0
        public async Task <IEnumerable <TreeNode <TvRequests, List <ChildRequests> > > > SearchTvRequestTree(string search)
        {
            var allRequests = TvRepository.Get();
            var results     = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();

            return(ParseIntoTreeNode(results));
        }
Example #5
0
        public async Task RemoveTvRequest(int requestId)
        {
            var request = await TvRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId);

            await TvRepository.Delete(request);

            await _mediaCacheService.Purge();
        }
Example #6
0
        public async Task RemoveTvRequest(int requestId)
        {
            var request = await TvRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId);

            await Audit.Record(AuditType.Deleted, AuditArea.TvRequest, $"Deleting Request {request.Title}", Username);

            await TvRepository.Delete(request);
        }
Example #7
0
        public async Task UpdateRootPath(int requestId, int rootPath)
        {
            var allRequests = TvRepository.Get();
            var results     = await allRequests.FirstOrDefaultAsync(x => x.Id == requestId);

            results.RootFolder = rootPath;

            await TvRepository.Update(results);
        }
Example #8
0
        public async Task UpdateQualityProfile(int requestId, int profileId)
        {
            var allRequests = TvRepository.Get();
            var results     = await allRequests.FirstOrDefaultAsync(x => x.Id == requestId);

            results.QualityOverride = profileId;

            await TvRepository.Update(results);
        }
Example #9
0
        public async Task <IEnumerable <TreeNode <TvRequests, List <ChildRequests> > > > GetRequestsTreeNode(int count, int position)
        {
            var allRequests = await TvRepository.Get()
                              .Include(x => x.ChildRequests)
                              .ThenInclude(x => x.SeasonRequests)
                              .ThenInclude(x => x.Episodes)
                              .Skip(position).Take(count).ToListAsync();

            return(ParseIntoTreeNode(allRequests));
        }
Example #10
0
        public async Task <TvRequests> UpdateTvRequest(TvRequests request)
        {
            await Audit.Record(AuditType.Updated, AuditArea.TvRequest, $"Updated Request {request.Title}", Username);

            var allRequests = TvRepository.Get();
            var results     = await allRequests.FirstOrDefaultAsync(x => x.Id == request.Id);

            await TvRepository.Update(results);

            return(results);
        }
Example #11
0
        public async Task <int> GetTotal()
        {
            var shouldHide = await HideFromOtherUsers();

            if (shouldHide.Hide)
            {
                return(await TvRepository.Get(shouldHide.UserId).CountAsync());
            }
            else
            {
                return(await TvRepository.Get().CountAsync());
            }
        }
Example #12
0
 public async Task<IEnumerable<TreeNode<TvRequests, List<ChildRequests>>>> SearchTvRequestTree(string search)
 {
     var shouldHide = await HideFromOtherUsers();
     IQueryable<TvRequests> allRequests;
     if (shouldHide.Hide)
     {
         allRequests = TvRepository.Get(shouldHide.UserId);
     }
     else
     {
         allRequests = TvRepository.Get();
     }
     var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();
     return ParseIntoTreeNode(results);
 }
Example #13
0
        public async Task<TvRequests> UpdateTvRequest(TvRequests request)
        {
            await Audit.Record(AuditType.Updated, AuditArea.TvRequest, $"Updated Request {request.Title}", Username);
            var allRequests = TvRepository.Get();
            var results = await allRequests.FirstOrDefaultAsync(x => x.Id == request.Id);

            results.TvDbId = request.TvDbId;
            results.ImdbId = request.ImdbId;
            results.Overview = request.Overview;
            results.PosterPath = PosterPathHelper.FixPosterPath(request.PosterPath);
            results.QualityOverride = request.QualityOverride;
            results.RootFolder = request.RootFolder;
            
            await TvRepository.Update(results);
            return results;
        }
Example #14
0
        public async Task <TvRequests> UpdateTvRequest(TvRequests request)
        {
            var allRequests = TvRepository.Get();
            var results     = await allRequests.FirstOrDefaultAsync(x => x.Id == request.Id);

            results.TvDbId          = request.TvDbId;
            results.ImdbId          = request.ImdbId;
            results.Overview        = request.Overview;
            results.PosterPath      = PosterPathHelper.FixPosterPath(request.PosterPath);
            results.Background      = PosterPathHelper.FixBackgroundPath(request.Background);
            results.QualityOverride = request.QualityOverride;
            results.RootFolder      = request.RootFolder;

            await TvRepository.Update(results);

            return(results);
        }
Example #15
0
        public async Task<IEnumerable<TvRequests>> GetRequests()
        {
            var shouldHide = await HideFromOtherUsers();
            IQueryable<TvRequests> allRequests;
            if (shouldHide.Hide)
            {
                allRequests = TvRepository.Get(shouldHide.UserId);

                FilterChildren(allRequests, shouldHide);
            }
            else
            {
                allRequests = TvRepository.Get();
            }

            return await allRequests.ToListAsync();
        }
Example #16
0
        public async Task <IEnumerable <TvRequests> > SearchTvRequest(string search)
        {
            var shouldHide = await HideFromOtherUsers();

            IQueryable <TvRequests> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = TvRepository.Get(shouldHide.UserId);
            }
            else
            {
                allRequests = TvRepository.Get();
            }
            var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync();

            results.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
            return(results);
        }
Example #17
0
        public async Task <IEnumerable <TvRequests> > GetRequests()
        {
            var shouldHide = await HideFromOtherUsers();

            List <TvRequests> allRequests;

            if (shouldHide.Hide)
            {
                allRequests = await TvRepository.Get(shouldHide.UserId).ToListAsync();

                FilterChildren(allRequests, shouldHide);
            }
            else
            {
                allRequests = await TvRepository.Get().ToListAsync();
            }

            allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); });
            return(allRequests);
        }
Example #18
0
        public async Task <TvRequests> GetTvRequest(int requestId)
        {
            var shouldHide = await HideFromOtherUsers();

            TvRequests request;

            if (shouldHide.Hide)
            {
                request = await TvRepository.Get(shouldHide.UserId).Where(x => x.Id == requestId).FirstOrDefaultAsync();

                FilterChildren(request, shouldHide);
            }
            else
            {
                request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync();
            }

            await CheckForSubscription(shouldHide, request);

            return(request);
        }
Example #19
0
        public async Task <IEnumerable <TvRequests> > GetRequests()
        {
            var allRequests = TvRepository.Get();

            return(await allRequests.ToListAsync());
        }
Example #20
0
        public async Task <RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
        {
            var user = await GetUser();

            var canRequestOnBehalf = false;

            if (tv.RequestOnBehalf.HasValue())
            {
                canRequestOnBehalf = await UserManager.IsInRoleAsync(user, OmbiRoles.PowerUser) || await UserManager.IsInRoleAsync(user, OmbiRoles.Admin);

                if (!canRequestOnBehalf)
                {
                    return(new RequestEngineResult
                    {
                        Result = false,
                        Message = "You do not have the correct permissions to request on behalf of users!",
                        ErrorMessage = $"You do not have the correct permissions to request on behalf of users!"
                    });
                }
            }

            var tvBuilder = new TvShowRequestBuilder(TvApi, MovieDbApi, _logger);

            (await tvBuilder
             .GetShowInfo(tv.TvDbId))
            .CreateTvList(tv)
            .CreateChild(tv, canRequestOnBehalf ? tv.RequestOnBehalf : user.Id);

            await tvBuilder.BuildEpisodes(tv);

            var ruleResults = await RunRequestRules(tvBuilder.ChildRequest);

            var results = ruleResults as RuleResult[] ?? ruleResults.ToArray();

            if (results.Any(x => !x.Success))
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = results.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message)).Message
                });
            }

            // Check if we have auto approved the request, if we have then mark the episodes as approved
            if (tvBuilder.ChildRequest.Approved)
            {
                foreach (var seasons in tvBuilder.ChildRequest.SeasonRequests)
                {
                    foreach (var ep in seasons.Episodes)
                    {
                        ep.Approved  = true;
                        ep.Requested = true;
                    }
                }
            }

            var existingRequest = await TvRepository.Get().FirstOrDefaultAsync(x => x.TvDbId == tv.TvDbId);

            if (existingRequest != null)
            {
                // Remove requests we already have, we just want new ones
                foreach (var existingSeason in existingRequest.ChildRequests)
                {
                    foreach (var existing in existingSeason.SeasonRequests)
                    {
                        var newChild = tvBuilder.ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == existing.SeasonNumber);
                        if (newChild != null)
                        {
                            // We have some requests in this season...
                            // Let's find the episodes.
                            foreach (var existingEp in existing.Episodes)
                            {
                                var duplicateEpisode = newChild.Episodes.FirstOrDefault(x => x.EpisodeNumber == existingEp.EpisodeNumber);
                                if (duplicateEpisode != null)
                                {
                                    // Remove it.
                                    newChild.Episodes.Remove(duplicateEpisode);
                                }
                            }
                            if (!newChild.Episodes.Any())
                            {
                                // We may have removed all episodes
                                tvBuilder.ChildRequest.SeasonRequests.Remove(newChild);
                            }
                        }
                    }
                }

                // Remove the ID since this is a new child
                // This was a TVDBID for the request rules to run
                tvBuilder.ChildRequest.Id = 0;
                if (!tvBuilder.ChildRequest.SeasonRequests.Any())
                {
                    // Looks like we have removed them all! They were all duplicates...
                    return(new RequestEngineResult
                    {
                        Result = false,
                        ErrorCode = ErrorCode.AlreadyRequested,
                        ErrorMessage = "This has already been requested"
                    });
                }
                return(await AddExistingRequest(tvBuilder.ChildRequest, existingRequest, tv.RequestOnBehalf, tv.RootFolderOverride.GetValueOrDefault(), tv.QualityPathOverride.GetValueOrDefault()));
            }

            // This is a new request
            var newRequest = tvBuilder.CreateNewRequest(tv);

            return(await AddRequest(newRequest.NewRequest, tv.RequestOnBehalf));
        }
Example #21
0
        public async Task <RequestEngineResult> RequestTvShow(TvRequestViewModel tv)
        {
            var user = await GetUser();

            var tvBuilder = new TvShowRequestBuilder(TvApi, MovieDbApi);

            (await tvBuilder
             .GetShowInfo(tv.TvDbId))
            .CreateTvList(tv)
            .CreateChild(tv, user.Id);

            await tvBuilder.BuildEpisodes(tv);

            var ruleResults = await RunRequestRules(tvBuilder.ChildRequest);

            var results = ruleResults as RuleResult[] ?? ruleResults.ToArray();

            if (results.Any(x => !x.Success))
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = results.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message)).Message
                });
            }

            // Check if we have auto approved the request, if we have then mark the episodes as approved
            if (tvBuilder.ChildRequest.Approved)
            {
                foreach (var seasons in tvBuilder.ChildRequest.SeasonRequests)
                {
                    foreach (var ep in seasons.Episodes)
                    {
                        ep.Approved  = true;
                        ep.Requested = true;
                    }
                }
            }

            await Audit.Record(AuditType.Added, AuditArea.TvRequest, $"Added Request {tvBuilder.ChildRequest.Title}", Username);

            var existingRequest = await TvRepository.Get().FirstOrDefaultAsync(x => x.TvDbId == tv.TvDbId);

            if (existingRequest != null)
            {
                // Remove requests we already have, we just want new ones
                foreach (var existingSeason in existingRequest.ChildRequests)
                {
                    foreach (var existing in existingSeason.SeasonRequests)
                    {
                        var newChild = tvBuilder.ChildRequest.SeasonRequests.FirstOrDefault(x => x.SeasonNumber == existing.SeasonNumber);
                        if (newChild != null)
                        {
                            // We have some requests in this season...
                            // Let's find the episodes.
                            foreach (var existingEp in existing.Episodes)
                            {
                                var duplicateEpisode = newChild.Episodes.FirstOrDefault(x => x.EpisodeNumber == existingEp.EpisodeNumber);
                                if (duplicateEpisode != null)
                                {
                                    // Remove it.
                                    newChild.Episodes.Remove(duplicateEpisode);
                                }
                            }
                            if (!newChild.Episodes.Any())
                            {
                                // We may have removed all episodes
                                tvBuilder.ChildRequest.SeasonRequests.Remove(newChild);
                            }
                        }
                    }
                }

                // Remove the ID since this is a new child
                tvBuilder.ChildRequest.Id = 0;
                if (!tvBuilder.ChildRequest.SeasonRequests.Any())
                {
                    // Looks like we have removed them all! They were all duplicates...
                    return(new RequestEngineResult
                    {
                        Result = false,
                        ErrorMessage = "This has already been requested"
                    });
                }
                return(await AddExistingRequest(tvBuilder.ChildRequest, existingRequest));
            }

            // This is a new request
            var newRequest = tvBuilder.CreateNewRequest(tv);

            return(await AddRequest(newRequest.NewRequest));
        }