Пример #1
0
        private async Task <IEnumerable <RoleManagerViewModel> > GetUserRolesList(CancellationToken cancellationToken)
        {
            var users         = new List <RoleManagerViewModel>();
            var readonlyUsers = (await _roleManager.GetUserIdsInRoleAsync(RoleNameConstants.UserRole, cancellationToken)).ToList();

            var adminUsers = (await _roleManager.GetUserIdsInRoleAsync(RoleNameConstants.AdminRole, cancellationToken)).ToList();

            readonlyUsers.AddRange(adminUsers);


            if (_contextService.IsSuperUser())
            {
                var superAdminUsers = (await _roleManager.GetUserIdsInRoleAsync(RoleNameConstants.SuperAdminRole, cancellationToken)).ToList();
                readonlyUsers.AddRange(superAdminUsers);
            }


            foreach (var user in readonlyUsers.Distinct())
            {
                var x = await _userManager.FindByIdAsync(user);

                users.Add(new RoleManagerViewModel()
                {
                    Email             = x.UserName,
                    IsInUserRole      = await _roleManager.IsInRoleAsync(x, RoleNameConstants.UserRole, cancellationToken),
                    IsInEditorRole    = await _roleManager.IsInRoleAsync(x, RoleNameConstants.AdminRole, cancellationToken),
                    IsInSuperUserRole = await _roleManager.IsInRoleAsync(x, RoleNameConstants.SuperAdminRole, cancellationToken),
                    Id = x.Id
                });
            }

            return(users.Where(t => t.Email != User.Identity.Name)); // filter out the current logged in user from the list;
        }