152 lines
5.0 KiB
Plaintext
152 lines
5.0 KiB
Plaintext
@page "/admin/UsersManager"
|
|
@using OrdersManagementDataModel.Dtos
|
|
@using Syncfusion.Blazor.Grids
|
|
@using Action = Syncfusion.Blazor.Grids.Action
|
|
@* @inject UserService UserService *@
|
|
@* @inject RoleService RoleService *@
|
|
@* @inject FunctionService FunctionService *@
|
|
|
|
<h3>Zarządzanie Użytkownikami i Rolami</h3>
|
|
<br />
|
|
|
|
<!-- Grid dla użytkowników -->
|
|
<h4>Użytkownicy</h4>
|
|
<SfGrid DataSource="@UserList" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
|
|
<GridColumns>
|
|
<GridColumn Field="@nameof(UserDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.Login)" HeaderText="Login" Width="100"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.Email)" HeaderText="Email" Width="150"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.FirstName)" HeaderText="Imię" Width="100"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.LastName)" HeaderText="Nazwisko" Width="100"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.IsActive)" HeaderText="Aktywny" Width="80"></GridColumn>
|
|
<GridColumn Field="@nameof(UserDto.CreatedDate)" HeaderText="Utworzono" Format="d" Width="120"></GridColumn>
|
|
</GridColumns>
|
|
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
|
|
<GridEvents OnActionBegin="UserActionBegin" OnActionComplete="UserActionComplete" TValue="UserDto"></GridEvents>
|
|
</SfGrid>
|
|
<br />
|
|
|
|
<!-- Grid dla ról -->
|
|
<h4>Role</h4>
|
|
<SfGrid DataSource="@Roles" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
|
|
<GridColumns>
|
|
<GridColumn Field="@nameof(RoleDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
|
|
<GridColumn Field="@nameof(RoleDto.Name)" HeaderText="Nazwa" Width="150"></GridColumn>
|
|
</GridColumns>
|
|
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
|
|
<GridEvents OnActionBegin="RoleActionBegin" OnActionComplete="RoleActionComplete" TValue="RoleDto"></GridEvents>
|
|
</SfGrid>
|
|
<br />
|
|
|
|
<!-- Grid dla funkcji -->
|
|
<h4>Funkcje</h4>
|
|
<SfGrid DataSource="@Functions" AllowPaging="true" ShowColumnMenu="true" Toolbar="@(new List<string> { "Add", "Edit", "Delete", "Cancel", "Update" })">
|
|
<GridColumns>
|
|
<GridColumn Field="@nameof(FunctionDto.Id)" IsPrimaryKey="true" HeaderText="ID" Width="70"></GridColumn>
|
|
<GridColumn Field="@nameof(FunctionDto.RoleId)" HeaderText="ID Roli" Width="70"></GridColumn>
|
|
<GridColumn Field="@nameof(FunctionDto.Name)" HeaderText="Nazwa Funkcji" Width="200"></GridColumn>
|
|
</GridColumns>
|
|
<GridEditSettings AllowDeleting="true" ShowDeleteConfirmDialog="true" AllowAdding="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
|
|
<GridEvents OnActionBegin="FunctionActionBegin" OnActionComplete="FunctionActionComplete" TValue="FunctionDto"></GridEvents>
|
|
</SfGrid>
|
|
|
|
@code {
|
|
private List<UserDto> UserList { get; set; } = new();
|
|
private List<RoleDto> Roles { get; set; } = new();
|
|
private List<FunctionDto> Functions { get; set; } = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await LoadUsers();
|
|
await LoadRoles();
|
|
await LoadFunctions();
|
|
}
|
|
|
|
// Użytkownicy
|
|
private async Task UserActionBegin(ActionEventArgs<UserDto> args)
|
|
{
|
|
// if (args.RequestType.Equals(Action.Delete))
|
|
// {
|
|
// await UserService.DeleteUserAsync(args.Data.Id);
|
|
// }
|
|
// else if (args.RequestType.Equals(Action.Add))
|
|
// {
|
|
// args.Data.RowPointer = Guid.NewGuid();
|
|
// }
|
|
}
|
|
|
|
private async Task UserActionComplete(ActionEventArgs<UserDto> args)
|
|
{
|
|
switch (args.RequestType)
|
|
{
|
|
case Action.Delete:
|
|
case Action.Save:
|
|
await LoadUsers();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async Task LoadUsers()
|
|
{
|
|
//Users = (await UserService.GetUsersAsync() ?? Array.Empty<UserDto>()).ToList();
|
|
}
|
|
|
|
// Role
|
|
private async Task RoleActionBegin(ActionEventArgs<RoleDto> args)
|
|
{
|
|
// if (args.RequestType.Equals(Action.Delete))
|
|
// {
|
|
// await RoleService.DeleteRoleAsync(args.Data.Id);
|
|
// }
|
|
// else if (args.RequestType.Equals(Action.Add))
|
|
// {
|
|
// args.Data.RowPointer = Guid.NewGuid();
|
|
// }
|
|
}
|
|
|
|
private async Task RoleActionComplete(ActionEventArgs<RoleDto> args)
|
|
{
|
|
switch (args.RequestType)
|
|
{
|
|
case Action.Delete:
|
|
case Action.Save:
|
|
await LoadRoles();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async Task LoadRoles()
|
|
{
|
|
//Roles = (await RoleService.GetRolesAsync() ?? Array.Empty<RoleDto>()).ToList();
|
|
}
|
|
|
|
// Funkcje
|
|
private async Task FunctionActionBegin(ActionEventArgs<FunctionDto> args)
|
|
{
|
|
if (args.RequestType.Equals(Action.Delete))
|
|
{
|
|
//await FunctionService.DeleteFunctionAsync(args.Data.Id);
|
|
}
|
|
else if (args.RequestType.Equals(Action.Add))
|
|
{
|
|
args.Data.RowPointer = Guid.NewGuid();
|
|
}
|
|
}
|
|
|
|
private async Task FunctionActionComplete(ActionEventArgs<FunctionDto> args)
|
|
{
|
|
switch (args.RequestType)
|
|
{
|
|
case Action.Delete:
|
|
case Action.Save:
|
|
await LoadFunctions();
|
|
break;
|
|
}
|
|
}
|
|
|
|
private async Task LoadFunctions()
|
|
{
|
|
//Functions = (await FunctionService.GetFunctionsAsync() ?? Array.Empty<FunctionDto>()).ToList();
|
|
}
|
|
}
|