@using Hcs.WebApp.Services @using Microsoft.AspNetCore.Identity @using Microsoft.EntityFrameworkCore @inject UserManager UserManager; @inject RoleManager RoleManager @inject UsersService UsersService @inject DialogService DialogService @errorMessage @if (!string.IsNullOrEmpty(Input.Password)) { } @code { sealed class InputModel { public string UserName { get; set; } 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 AppUserWithRole UserWithRole { get; set; } [SupplyParameterFromForm] InputModel Input { get; set; } = new(); protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); Input.UserName = UserWithRole.User.UserName; Input.RoleDisabled = CurrentUserId == UserWithRole.User.Id; Input.RoleId = UserWithRole.Role.Id; 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(UserWithRole.User.Id, 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); } }