Add new user creation
This commit is contained in:
112
Hcs.WebApp/Components/Pages/Management/Users.razor
Normal file
112
Hcs.WebApp/Components/Pages/Management/Users.razor
Normal file
@ -0,0 +1,112 @@
|
||||
@page "/management/users"
|
||||
|
||||
@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
|
||||
|
||||
<PageTitle>Пользователи</PageTitle>
|
||||
|
||||
<AuthorizedContent Roles="@AppRole.ADMINISTRATOR_TYPE">
|
||||
<Content>
|
||||
<RadzenStack>
|
||||
<RadzenRow AlignItems="AlignItems.Center">
|
||||
<RadzenColumn Size="12" SizeMD="6">
|
||||
<RadzenText Text="Пользователи" TextStyle="TextStyle.H5" class="rz-m-0" />
|
||||
</RadzenColumn>
|
||||
<RadzenColumn Size="12" SizeMD="6">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.End" Gap="0.5rem">
|
||||
<RadzenButton Icon="add_circle_outline" Text="Создать" Click="@AddUser" ButtonStyle="ButtonStyle.Primary" />
|
||||
</RadzenStack>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
<RadzenRow>
|
||||
<RadzenColumn SizeMD="12">
|
||||
<!--<RadzenAlert AlertStyle="AlertStyle.Danger" Variant="Variant.Flat" Shade="Shade.Lighter" Title="" Visible="@errorVisible">@error</RadzenAlert>-->
|
||||
<RadzenDataGrid TItem="AppUserWithRole" Data="@usersWithRoles" RowSelect="@EditUser" IsLoading="@isLoading" AllowFiltering="true" AllowPaging="true" ShowPagingSummary="true" PageSizeOptions=@(new int[] { 5, 10, 20, 30 }) AllowSorting="true">
|
||||
<Columns>
|
||||
<RadzenDataGridColumn TItem="AppUserWithRole" Property="User.UserName" Title="Логин" />
|
||||
<RadzenDataGridColumn TItem="AppUserWithRole" Property="Role.Name" Title="Роль" />
|
||||
<RadzenDataGridColumn TItem="AppUserWithRole" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Width="70px">
|
||||
<Template Context="userWithRole">
|
||||
<RadzenButton Click="@(() => DeleteUser(userWithRole))" @onclick:stopPropagation="true" ButtonStyle="ButtonStyle.Danger" Icon="close" Size="ButtonSize.Small" />
|
||||
</Template>
|
||||
</RadzenDataGridColumn>
|
||||
</Columns>
|
||||
</RadzenDataGrid>
|
||||
</RadzenColumn>
|
||||
</RadzenRow>
|
||||
</RadzenStack>
|
||||
</Content>
|
||||
</AuthorizedContent>
|
||||
|
||||
@code {
|
||||
IEnumerable<AppUserWithRole> 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<AddUser>(
|
||||
"Создание пользователя",
|
||||
null,
|
||||
new DialogOptions()
|
||||
{
|
||||
Width = "420px",
|
||||
ShowClose = false,
|
||||
CloseDialogOnEsc = false,
|
||||
CloseDialogOnOverlayClick = false
|
||||
});
|
||||
|
||||
if (success)
|
||||
{
|
||||
await UpdateGrid();
|
||||
}
|
||||
}
|
||||
|
||||
async Task EditUser(AppUserWithRole userWithRole)
|
||||
{
|
||||
// TODO: Implement method
|
||||
}
|
||||
|
||||
async Task DeleteUser(AppUserWithRole userWithRole)
|
||||
{
|
||||
// TODO: Implement method
|
||||
}
|
||||
|
||||
async Task UpdateGrid()
|
||||
{
|
||||
isLoading = true;
|
||||
|
||||
usersWithRoles = await UsersService.GetUsersWithRole();
|
||||
|
||||
isLoading = false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user