public async Task <IActionResult> RemoveRoleFromUser(string userId, string roleName) { IdentityUser userFound = await _userManager.FindByIdAsync(userId); if (userFound == null) { return(RedirectToAction(nameof(UserList))); } var result = await _userManager.RemoveFromRoleAsync(userFound, roleName); if (result.Succeeded) { return(RedirectToAction("RolesManagement", new { id = userId })); } IList <string> userRoles = await _userManager.GetRolesAsync(userFound); List <IdentityRole> identityRoles = _roleManager.Roles.ToList(); RolesManagementVM viewModel = new RolesManagementVM(userId, userRoles, identityRoles); ViewBag.ErrorMsg = "Failed to change the role for the user"; return(View("RolesManagement", viewModel)); }
public async Task <IActionResult> RolesManagement(string id) { IdentityUser userFound = await _userManager.FindByIdAsync(id); if (userFound == null) { return(RedirectToAction(nameof(UserList))); } IList <string> userRoles = await _userManager.GetRolesAsync(userFound); List <IdentityRole> identityRoles = _roleManager.Roles.ToList(); RolesManagementVM viewModel = new RolesManagementVM(id, userRoles, identityRoles); return(View(viewModel)); }