little modifications to users
This commit is contained in:
parent
07f466d74b
commit
d58a8702b3
8
.idea/.idea.UserService/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.UserService/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ContentModelUserStore">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/.idea.UserService/.idea/modules.xml
generated
Normal file
8
.idea/.idea.UserService/.idea/modules.xml
generated
Normal 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>
|
6
.idea/.idea.UserService/.idea/projectSettingsUpdater.xml
generated
Normal file
6
.idea/.idea.UserService/.idea/projectSettingsUpdater.xml
generated
Normal 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
6
.idea/.idea.UserService/.idea/vcs.xml
generated
Normal 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
15
.idea/.idea.UserService/riderModule.iml
generated
Normal 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>
|
@ -52,7 +52,7 @@ namespace UserService.DatabaseLayer.DataModels
|
|||||||
public Node? Parent { get; set; } //Parent
|
public Node? Parent { get; set; } //Parent
|
||||||
public int? ParentId { get; set; }
|
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;
|
public int Level => Parent?.Level + 1 ?? 0;
|
||||||
|
|
||||||
|
@ -38,11 +38,12 @@ namespace UserService.DatabaseLayer.Repository
|
|||||||
await db.SaveChangesAsync(token);
|
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();
|
await using var db = new UserServiceDbContext();
|
||||||
Context(db).Update(entity);
|
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)
|
public async Task DeleteAsync(T entity, CancellationToken token = default)
|
||||||
|
@ -13,7 +13,7 @@ namespace UserService.DatabaseLayer.Repository
|
|||||||
Task<IReadOnlyList<T>> GetAllAsync(Expression<Func<T, bool>>? predicate = null, CancellationToken token = default);
|
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<T?> GetAsync(Expression<Func<T, bool>> predicate, CancellationToken token = default);
|
||||||
Task AddAsync(T entity, 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);
|
Task DeleteAsync(T entity, CancellationToken token = default);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
UserService.db
BIN
UserService.db
Binary file not shown.
@ -12,7 +12,7 @@
|
|||||||
}
|
}
|
||||||
else
|
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">
|
<DataGridCommandColumn TItem="User">
|
||||||
<NewCommandTemplate>
|
<NewCommandTemplate>
|
||||||
<Button Color="Color.Success" Clicked="@context.Clicked" title="Create user"><i class="fa fa-user-plus"></i></Button>
|
<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.FirstName)" Caption="First Name" Editable="true"/>
|
||||||
<DataGridColumn TItem="User" Field="@nameof(User.LastName)" Caption="Last 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.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"/>
|
<DataGridCheckColumn TItem="User" Field="@nameof(User.IsActive)" Caption="Active" Editable="true"/>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
}
|
}
|
@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Blazorise.DataGrid;
|
using Blazorise.DataGrid;
|
||||||
|
using Microsoft.JSInterop;
|
||||||
using UserService.DatabaseLayer.DataModels;
|
using UserService.DatabaseLayer.DataModels;
|
||||||
using UserService.DatabaseLayer.Repository;
|
using UserService.DatabaseLayer.Repository;
|
||||||
|
|
||||||
@ -12,8 +13,7 @@ namespace UserService.Pages
|
|||||||
[Inject] private IUsersRepository UsersRepository { get; set; } = null!;
|
[Inject] private IUsersRepository UsersRepository { get; set; } = null!;
|
||||||
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
[Inject] private IOrganizationUnitsRepository OrganizationUnitsRepository { get; set; } = null!;
|
||||||
|
|
||||||
protected bool DialogIsOpen { get; set; }
|
[Inject] private IJSRuntime JsRuntime { get; set; } = null!;
|
||||||
protected User? UserToEdit { get; private set; }
|
|
||||||
|
|
||||||
protected IReadOnlyList<User>? Users { get; private set; }
|
protected IReadOnlyList<User>? Users { get; private set; }
|
||||||
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; private set; }
|
protected IReadOnlyList<OrganizationUnit>? OrganizationUnits { get; private set; }
|
||||||
@ -24,29 +24,31 @@ namespace UserService.Pages
|
|||||||
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
OrganizationUnits = await OrganizationUnitsRepository.GetAllAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void EditUser(User user)
|
protected async Task RowInsertedCallback(SavedRowItem<User, Dictionary<string, object>> arg)
|
||||||
{
|
{
|
||||||
DialogIsOpen = true;
|
var user = arg.Item;
|
||||||
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;
|
|
||||||
user.ParentId = -2;
|
user.ParentId = -2;
|
||||||
await UsersRepository.AddAsync(user);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user