54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Blazorise.DataGrid;
|
|
using Microsoft.JSInterop;
|
|
using UserService.DatabaseLayer.DataModels;
|
|
using UserService.DatabaseLayer.Repository;
|
|
|
|
namespace UserService.Pages
|
|
{
|
|
public class UsersBase : ComponentBase
|
|
{
|
|
[Inject] private IUsersRepository UsersRepository { get; set; } = null!;
|
|
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
|
|
|
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
|
|
|
|
protected IReadOnlyList<User>? Users { get; private set; }
|
|
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; private set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
Users = await UsersRepository.GetAllAsync();
|
|
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
|
}
|
|
|
|
protected async Task RowInsertedCallback(SavedRowItem<User, Dictionary<string, object>> arg)
|
|
{
|
|
var user = arg.Item;
|
|
user.ParentId = -2;
|
|
await UsersRepository.AddAsync(user);
|
|
}
|
|
|
|
protected async Task RowDeletingCallback(CancellableRowChange<User> arg)
|
|
{
|
|
var confirmed = await JsRuntime.InvokeAsync<bool>("confirm",
|
|
$"You are about to delete the user {arg.Item.FullName}. Are you sure?").ConfigureAwait(false);
|
|
if (confirmed)
|
|
{
|
|
await UsersRepository.DeleteAsync(arg.Item).ConfigureAwait(false);
|
|
return;
|
|
}
|
|
|
|
arg.Cancel = true;
|
|
}
|
|
|
|
protected async Task RowUpdatingCallback(CancellableRowChange<User, Dictionary<string, object>> arg)
|
|
{
|
|
var result = await UsersRepository.UpdateAsync(arg.Item);
|
|
arg.Cancel = !result;
|
|
}
|
|
|
|
}
|
|
} |