示例#1
0
        public void OnGet()
        {
            var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name;

            Users    = UserManagers.GetUsersInRoleAsync(rolename).Result.ToList();
            RoleName = rolename;
        }
示例#2
0
        public IActionResult OnGetAddUserRole(string roleId)
        {
            var rolename       = RoleManagers.FindByIdAsync(RoleId).Result.Name;
            var Usersinrole    = UserManagers.GetUsersInRoleAsync(rolename).Result.ToList();
            var UserList       = _context.Users.ToList();
            var Usersnotinrole = UserList.Except(Usersinrole).ToList();
            var Usersrole      = new UserRole();

            Usersrole.RoleId = roleId;
            Usersrole.Users  = Usersnotinrole;
            return(Partial("_adduserole", Usersrole));
        }
示例#3
0
        public IActionResult OnGetAddUserToRole(string userId)
        {
            var UsersId  = UserManagers.FindByIdAsync(userId).Result;
            var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name;
            var result1  = UserManagers.AddToRoleAsync(UsersId, rolename).Result;

            if (result1.Succeeded)
            {
                flashMessage = "User added to role";
            }
            else
            {
                flashMessage = "Error adding user to role";
            }
            return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
        }
示例#4
0
        public IActionResult OnGetDeleteUserRole(string userId)
        {
            var UsersId  = UserManagers.FindByIdAsync(userId).Result;
            var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name;

            if (UsersId.Email == "*****@*****.**" && rolename == "Admin")
            {
                return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
            }
            else
            {
                var result1 = UserManagers.RemoveFromRoleAsync(UsersId, rolename).Result;
                if (result1.Succeeded)
                {
                    flashMessage = "User removed from role";
                }
                else
                {
                    flashMessage = "Error removing user from role";
                }
            }
            return(RedirectToPage("ViewUserRoles", new { RoleId = RoleId, flashMessage = flashMessage }));
        }