Add user manager page (#22)
Reviewed-on: #22
This commit was merged in pull request #22.
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
using GameIdeas.BlazorApp.Pages.Users.Filters;
|
||||
using GameIdeas.BlazorApp.Pages.Users.Gateways;
|
||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||
using GameIdeas.Shared.Dto;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace GameIdeas.BlazorApp.Pages.Users;
|
||||
|
||||
public partial class Users
|
||||
{
|
||||
[Inject] private IUserGateway UserGateway { get; set; } = default!;
|
||||
|
||||
private Popup? Popup;
|
||||
private bool IsLoading = false;
|
||||
private UserFilterParams FilterParams = new();
|
||||
private UserListDto UserList = new();
|
||||
private IEnumerable<RoleDto> Roles = [];
|
||||
private int CurrentPage = 1;
|
||||
private UserDto UserAdd = new();
|
||||
private UserDto? UserDelete;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await FetchData();
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private async Task FetchData(bool fetchRoles = true)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
if (fetchRoles)
|
||||
Roles = await UserGateway.GetRoles();
|
||||
|
||||
UserList = await UserGateway.GetUsers(FilterParams, CurrentPage);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleSubmitUser(UserDto user)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
await UserGateway.CreateUser(user);
|
||||
await FetchData(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
UserAdd = new();
|
||||
}
|
||||
|
||||
private async Task HandleUpdateUser(UserDto user)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
await UserGateway.UpdateUser(user);
|
||||
await FetchData(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task HandleRemoveUser()
|
||||
{
|
||||
Popup?.Close();
|
||||
|
||||
if (UserDelete?.Id == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
|
||||
await UserGateway.DeleteUser(UserDelete.Id);
|
||||
await FetchData(false);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsLoading = false;
|
||||
}
|
||||
|
||||
UserDelete = null;
|
||||
}
|
||||
private void HandleResetUser(UserDto args)
|
||||
{
|
||||
UserAdd = new();
|
||||
}
|
||||
private async Task HandleFilterChanged()
|
||||
{
|
||||
await FetchData(false);
|
||||
}
|
||||
private void HandleCancelPopupClicked()
|
||||
{
|
||||
Popup?.Close();
|
||||
}
|
||||
private void HandleOpenConfirmationPopup(UserDto user)
|
||||
{
|
||||
UserDelete = user;
|
||||
Popup?.Open();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user