@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 bool RoleDisabled { get; set; } 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 required string CurrentUserId { get; set; } [Parameter] public required string UserId { get; set; } [Parameter] public required string RoleId { get; set; } [SupplyParameterFromForm] InputModel Input { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); Input.RoleDisabled = CurrentUserId == UserId; Input.RoleId = RoleId; roles = await RoleManager.Roles.OrderBy(x => x.Priority).ToListAsync(); } async Task DoEditUserAsync(InputModel input) { if (inProgress) return; inProgress = true; hasError = false; try { await UsersService.UpdateUserAsync(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); } }