@using Hcs.WebApp.Services @using Microsoft.AspNetCore.Authorization @using Microsoft.AspNetCore.Identity @using Microsoft.EntityFrameworkCore @attribute [Authorize] @inject UserManager UserManager; @inject RoleManager RoleManager @inject UsersService UsersService @inject DialogService DialogService @errorMessage @if (!string.IsNullOrEmpty(Input.Password)) { } @code { sealed class InputModel { public string RoleId { get; set; } public string Password { get; set; } = ""; public string ConfirmPassword { get; set; } = ""; } IEnumerable roles; bool inProgress; bool hasError; string errorMessage; [Parameter] public string UserId { get; set; } [Parameter] public string RoleId { get; set; } [SupplyParameterFromForm] InputModel Input { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); roles = await RoleManager.Roles.OrderBy(x => x.Priority).ToListAsync(); Input.RoleId = RoleId; } async Task DoEditUser(InputModel input) { if (inProgress) return; inProgress = true; hasError = false; try { await UsersService.UpdateUser(UserId, input.RoleId, input.Password); DialogService.Close(true); } catch (Exception e) { hasError = true; errorMessage = e.Message; } finally { inProgress = false; } } void DoClose() { if (inProgress) return; DialogService.Close(false); } }