public void OnGet() { var rolename = RoleManagers.FindByIdAsync(RoleId).Result.Name; Users = UserManagers.GetUsersInRoleAsync(rolename).Result.ToList(); RoleName = rolename; }
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)); }
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 })); }
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 })); }