public async Task <IActionResult> RemoveFromRole(UserRoleFormModel model, int page, string searchTerm) { bool result = await this.userService.RemoveFromRoleAsync(model.UserId, model.Role); if (!result) { TempData.AddErrorMessage("Invalid identity details."); } else { TempData.AddSuccessMessage($"User successfully removed from the {model.Role} role."); } return(RedirectToAction(nameof(Index), new { page = page, searchTerm = searchTerm })); }
public async Task <IActionResult> RemoveFromRole(UserRoleFormModel model) { var roleExists = await this.roleManager.RoleExistsAsync(model.Role); var user = await this.userManager.FindByIdAsync(model.UserId); var userExists = user != null; if (!roleExists || !userExists) { ModelState.AddModelError(string.Empty, "Invalid identity details"); } if (!ModelState.IsValid) { return(RedirectToAction(nameof(Index))); } await this.userManager.RemoveFromRoleAsync(user, model.Role); TempData.AddSuccessMessage($"User {user.UserName} successfully removed from {model.Role} role!"); return(RedirectToAction(nameof(Index))); }