little modifications to users
This commit is contained in:
@ -12,7 +12,7 @@
|
||||
}
|
||||
else
|
||||
{
|
||||
<DataGrid TItem="User" Editable="true" EditMode="DataGridEditMode.Inline" Data="@Users" RowInserted="@RowInsertedCallback">
|
||||
<DataGrid TItem="User" Editable="true" EditMode="DataGridEditMode.Inline" RowRemoving="RowDeletingCallback" Data="@Users" RowInserted="RowInsertedCallback" RowUpdating="RowUpdatingCallback">
|
||||
<DataGridCommandColumn TItem="User">
|
||||
<NewCommandTemplate>
|
||||
<Button Color="Color.Success" Clicked="@context.Clicked" title="Create user"><i class="fa fa-user-plus"></i></Button>
|
||||
@ -29,7 +29,7 @@ else
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.FirstName)" Caption="First Name" Editable="true"/>
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.LastName)" Caption="Last Name" Editable="true"/>
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.EMail)" Caption="EMail" Editable="true"/>
|
||||
<DataGridColumn TItem="User" Field="@nameof(User.Parent)" Caption="Parent" Editable="false"/>
|
||||
<DataGridSelectColumn TItem="User" Field="@nameof(User.Parent)" Caption="Parent" Editable="true"/>
|
||||
<DataGridCheckColumn TItem="User" Field="@nameof(User.IsActive)" Caption="Active" Editable="true"/>
|
||||
</DataGrid>
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Blazorise.DataGrid;
|
||||
using Microsoft.JSInterop;
|
||||
using UserService.DatabaseLayer.DataModels;
|
||||
using UserService.DatabaseLayer.Repository;
|
||||
|
||||
@ -12,8 +13,7 @@ namespace UserService.Pages
|
||||
[Inject] private IUsersRepository UsersRepository { get; set; } = null!;
|
||||
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
||||
|
||||
protected bool DialogIsOpen { get; set; }
|
||||
protected User? UserToEdit { get; private set; }
|
||||
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
|
||||
|
||||
protected IReadOnlyList<User>? Users { get; private set; }
|
||||
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; private set; }
|
||||
@ -24,29 +24,31 @@ namespace UserService.Pages
|
||||
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected void EditUser(User user)
|
||||
protected async Task RowInsertedCallback(SavedRowItem<User, Dictionary<string, object>> arg)
|
||||
{
|
||||
DialogIsOpen = true;
|
||||
UserToEdit = user;
|
||||
}
|
||||
|
||||
protected async Task OkClick()
|
||||
{
|
||||
if (UserToEdit is null) return;
|
||||
await UsersRepository.UpdateAsync(UserToEdit).ConfigureAwait(false);
|
||||
DialogIsOpen = false;
|
||||
}
|
||||
|
||||
protected async Task DeleteUser(User user)
|
||||
{
|
||||
await UsersRepository.DeleteAsync(user).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
protected async Task RowInsertedCallback(SavedRowItem<User, Dictionary<string, object>> obj)
|
||||
{
|
||||
var user = obj.Item;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user