@page "/management/users"
@using Hcs.WebApp.Components.Dialogs
@using Hcs.WebApp.Services
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Identity
@using Microsoft.EntityFrameworkCore
@attribute [Authorize]
@inject AuthenticationStateProvider AuthenticationStateProvider
@inject UsersService UsersService
@inject DialogService DialogService
Пользователи
@code {
IEnumerable usersWithRoles;
bool isLoading;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
isLoading = true;
StateHasChanged();
var state = await AuthenticationStateProvider.GetAuthenticationStateAsync();
if (state.User.Identity?.IsAuthenticated ?? false)
{
usersWithRoles = await UsersService.GetUsersWithRole();
}
isLoading = false;
StateHasChanged();
}
}
async Task AddUser()
{
var success = await DialogService.OpenAsync(
"Создание пользователя",
null,
new DialogOptions()
{
Width = "420px",
ShowClose = false,
CloseDialogOnEsc = false,
CloseDialogOnOverlayClick = false
});
if (success)
{
await UpdateGrid();
}
}
async Task EditUser(AppUserWithRole userWithRole)
{
var success = await DialogService.OpenAsync(
"Редактирование пользователя",
new Dictionary()
{
{ nameof(Dialogs.EditUser.UserId), userWithRole.User.Id },
{ nameof(Dialogs.EditUser.RoleId), userWithRole.Role.Id }
},
new DialogOptions()
{
Width = "420px",
ShowClose = false,
CloseDialogOnEsc = false,
CloseDialogOnOverlayClick = false
});
if (success)
{
await UpdateGrid();
}
}
async Task DeleteUser(AppUserWithRole userWithRole)
{
// TODO: Implement method
}
async Task UpdateGrid()
{
isLoading = true;
usersWithRoles = await UsersService.GetUsersWithRole();
isLoading = false;
}
}