Exemplo n.º 1
0
        public async Task <RuleResult> Execute(BaseRequest obj)
        {
            if (obj.RequestType == RequestType.Movie)
            {
                var remainingLimitsModel = await _requestLimitService.GetRemainingMovieRequests();

                if (!remainingLimitsModel.HasLimit)
                {
                    return(Success());
                }

                if (remainingLimitsModel.Remaining < 1)
                {
                    return(Fail(Engine.ErrorCode.MovieRequestQuotaExceeded, "You have exceeded your Movie request quota!"));
                }
            }
            if (obj.RequestType == RequestType.TvShow)
            {
                var remainingLimitsModel = await _requestLimitService.GetRemainingTvRequests();

                if (!remainingLimitsModel.HasLimit)
                {
                    return(Success());
                }

                var child        = (ChildRequests)obj;
                var requestCount = 0;
                // Get the count of requests to be made
                foreach (var s in child.SeasonRequests)
                {
                    requestCount += s.Episodes.Count;
                }

                if ((remainingLimitsModel.Remaining - requestCount) < 0)
                {
                    return(Fail(Engine.ErrorCode.TvRequestQuotaExceeded, "You have exceeded your Episode request quota!"));
                }
            }
            if (obj.RequestType == RequestType.Album)
            {
                var remainingLimitsModel = await _requestLimitService.GetRemainingMusicRequests();

                if (!remainingLimitsModel.HasLimit)
                {
                    return(Success());
                }

                if (remainingLimitsModel.Remaining < 1)
                {
                    return(Fail(Engine.ErrorCode.AlbumRequestQuotaExceeded, "You have exceeded your Album request quota!"));
                }
            }
            return(Success());
        }
Exemplo n.º 2
0
        private async Task <UserViewModel> GetUserWithRoles(OmbiUser user)
        {
            var userRoles = await UserManager.GetRolesAsync(user);

            var vm = new UserViewModel
            {
                Alias                   = user.Alias,
                UserName                = user.UserName,
                Id                      = user.Id,
                EmailAddress            = user.Email,
                UserType                = (Core.Models.UserType)(int) user.UserType,
                Claims                  = new List <ClaimCheckboxes>(),
                LastLoggedIn            = user.LastLoggedIn,
                HasLoggedIn             = user.LastLoggedIn.HasValue,
                EpisodeRequestLimit     = user.EpisodeRequestLimit ?? 0,
                MovieRequestLimit       = user.MovieRequestLimit ?? 0,
                MusicRequestLimit       = user.MusicRequestLimit ?? 0,
                MovieRequestLimitType   = user.MovieRequestLimitType ?? RequestLimitType.Week,
                EpisodeRequestLimitType = user.EpisodeRequestLimitType ?? RequestLimitType.Week,
                MusicRequestLimitType   = user.MusicRequestLimitType ?? RequestLimitType.Week,
                Language                = user.Language,
                StreamingCountry        = user.StreamingCountry
            };

            foreach (var role in userRoles)
            {
                vm.Claims.Add(new ClaimCheckboxes
                {
                    Value   = role,
                    Enabled = true
                });
            }

            // Add the missing claims
            var allRoles = await RoleManager.Roles.ToListAsync();

            var missing = allRoles.Select(x => x.Name).Except(userRoles);

            foreach (var role in missing)
            {
                vm.Claims.Add(new ClaimCheckboxes
                {
                    Value   = role,
                    Enabled = false
                });
            }

            if (vm.EpisodeRequestLimit > 0)
            {
                vm.EpisodeRequestQuota = await _requestLimitService.GetRemainingTvRequests(user);
            }

            if (vm.MovieRequestLimit > 0)
            {
                vm.MovieRequestQuota = await _requestLimitService.GetRemainingMovieRequests(user);
            }

            if (vm.MusicRequestLimit > 0)
            {
                vm.MusicRequestQuota = await _requestLimitService.GetRemainingMusicRequests(user);
            }

            // Get the quality profiles
            vm.UserQualityProfiles = await _userQualityProfiles.GetAll().FirstOrDefaultAsync(x => x.UserId == user.Id);

            if (vm.UserQualityProfiles == null)
            {
                vm.UserQualityProfiles = new UserQualityProfiles
                {
                    UserId = user.Id
                };
            }

            return(vm);
        }
Exemplo n.º 3
0
 public async Task <RequestQuotaCountModel> GetRemainingTvRequests()
 {
     return(await _requestLimitService.GetRemainingTvRequests());
 }