Exemplo n.º 1
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,
            };

            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 TvRequestEngine.GetRemainingRequests(user);
            }

            if (vm.MovieRequestLimit > 0)
            {
                vm.MovieRequestQuota = await MovieRequestEngine.GetRemainingRequests(user);
            }

            if (vm.MusicRequestLimit > 0)
            {
                vm.MusicRequestQuota = await MusicRequestEngine.GetRemainingRequests(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.º 2
0
 public async Task <RequestQuotaCountModel> GetRemainingTvRequests()
 {
     return(await TvRequestEngine.GetRemainingRequests());
 }