little modifications to users

This commit is contained in:
Holger Börchers 2020-08-06 22:57:25 +02:00
parent 07f466d74b
commit d58a8702b3
11 changed files with 74 additions and 28 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ContentModelUserStore">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/.idea.UserService/riderModule.iml" filepath="$PROJECT_DIR$/.idea/.idea.UserService/riderModule.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RiderProjectSettingsUpdater">
<option name="vcsConfiguration" value="2" />
</component>
</project>

6
.idea/.idea.UserService/.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

15
.idea/.idea.UserService/riderModule.iml generated Normal file
View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="RIDER_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$USER_HOME$/.nuget/packages/microsoft.net.test.sdk/16.6.1/build/netcoreapp2.1" />
<content url="file://$USER_HOME$/.nuget/packages/microsoft.testplatform.testhost/16.6.1/build/netcoreapp2.1/x64/testhost.dll" />
<content url="file://$USER_HOME$/.nuget/packages/microsoft.testplatform.testhost/16.6.1/build/netcoreapp2.1/x64/testhost.exe" />
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.17.0/build/netcoreapp2.1/NUnit3.TestAdapter.dll" />
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.17.0/build/netcoreapp2.1/NUnit3.TestAdapter.pdb" />
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.17.0/build/netcoreapp2.1/nunit.engine.api.dll" />
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.17.0/build/netcoreapp2.1/nunit.engine.core.dll" />
<content url="file://$USER_HOME$/.nuget/packages/nunit3testadapter/3.17.0/build/netcoreapp2.1/nunit.engine.dll" />
<content url="file://$MODULE_DIR$/../.." />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -52,7 +52,7 @@ namespace UserService.DatabaseLayer.DataModels
public Node? Parent { get; set; } //Parent
public int? ParentId { get; set; }
public override string ToString() => $"[{GetType().Name}] {Id:D5} {CommonName}";
public override string ToString() => CommonName;
public int Level => Parent?.Level + 1 ?? 0;

View File

@ -38,11 +38,12 @@ namespace UserService.DatabaseLayer.Repository
await db.SaveChangesAsync(token);
}
public async Task UpdateAsync(T entity, CancellationToken token = default)
public async Task<bool> UpdateAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
Context(db).Update(entity);
await db.SaveChangesAsync(token);
var items= await db.SaveChangesAsync(token);
return items > 0;
}
public async Task DeleteAsync(T entity, CancellationToken token = default)

View File

@ -13,7 +13,7 @@ namespace UserService.DatabaseLayer.Repository
Task<IReadOnlyList<T>> GetAllAsync(Expression<Func<T, bool>>? predicate = null, CancellationToken token = default);
Task<T?> GetAsync(Expression<Func<T, bool>> predicate, CancellationToken token = default);
Task AddAsync(T entity, CancellationToken token = default);
Task UpdateAsync(T entity, CancellationToken token = default);
Task<bool> UpdateAsync(T entity, CancellationToken token = default);
Task DeleteAsync(T entity, CancellationToken token = default);
}

Binary file not shown.

View File

@ -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>
}

View File

@ -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;
}
}
}