public async Task <IActionResult> Roles(Guid userId) { var user = await this.userManager.FindUserByIdAsync(userId); if (user != null) { this.ViewData["[UserName]"] = user.Name; var model = new RolesViewModel(); model.SetRoleOptions(await this.roleManager.GetRolesAsync()); model.SetSelectedRoles(await this.roleManager.GetUserRolesAsync(user)); return(this.View(model)); } return(this.NotFound()); }
public async Task <IActionResult> Roles(Guid userId, RolesViewModel model) { var user = await this.userManager.FindUserByIdAsync(userId); if (user != null) { var result = await this.Mediator.Send(new AssignRolesToUserCommand(user.Id, model?.SelectedRoles)); if (result.Succeeded) { this.ShowSuccessNotification($"Roles have been assigned successfully to {user.Name}"); return(this.RedirectToAction(nameof(this.GetAll))); } else { this.ShowErrorNotification("Roles have not been assigned successfully."); model.SetRoleOptions(await this.roleManager.GetRolesAsync()); return(this.View(model)); } } return(this.NotFound()); }