Fixed bugs

This commit is contained in:
Holger Börchers 2020-09-26 20:49:09 +02:00
parent b21781edde
commit 1811ea5a1a
7 changed files with 38 additions and 14 deletions

View File

@ -27,7 +27,7 @@ namespace UserService.DatabaseLayer.Repositories
await db.SaveChangesAsync(token).ConfigureAwait(false);
}
public async Task DeleteAsync(T entity, CancellationToken token = default)
public virtual async Task DeleteAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
Context(db).Remove(entity);
@ -45,7 +45,7 @@ namespace UserService.DatabaseLayer.Repositories
await using var db = new UserServiceDbContext();
return await Context(db).Include(x => x.Parent).FirstOrDefaultAsync(predicate, token).ConfigureAwait(false);
}
public async Task<bool> UpdateAsync(T entity, CancellationToken token = default)
public virtual async Task<bool> UpdateAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
Context(db).Update(entity);

View File

@ -22,6 +22,7 @@ namespace UserService.DatabaseLayer.Repositories
return await Context(db)
.Include(x => x.Parent)
.Include(x => x.Members)
.ThenInclude(x=> x.AttachedMember)
.WhereOrDefault(predicate)
.ToListAsync(token).ConfigureAwait(false);
}
@ -32,7 +33,16 @@ namespace UserService.DatabaseLayer.Repositories
return await Context(db)
.Include(x => x.Parent)
.Include(x => x.Members)
.ThenInclude(x=> x.AttachedMember)
.FirstOrDefaultAsync(predicate, token).ConfigureAwait(false);
}
public override async Task<bool> UpdateAsync(SecurityGroup entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
Context(db).Update(entity);
var items = await db.SaveChangesAsync(token).ConfigureAwait(false);
return items > 0;
}
}
}

View File

@ -0,0 +1,13 @@
// ReSharper disable once CheckNamespace
namespace System.Collections.Generic
{
public static class KeyValueExtensions
{
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> keyValuePair, out TKey key,
out TValue value)
{
key = keyValuePair.Key;
value = keyValuePair.Value;
}
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using UserService.Infrastructure.DataModels;
namespace UserService.Infrastructure.DataModels
namespace UserService.Infrastructure
{
public static class NodeExtensions
{
@ -12,11 +12,13 @@ namespace UserService.Infrastructure.DataModels
if (member == null) throw new ArgumentNullException(nameof(member));
if (values == null) throw new ArgumentNullException(nameof(values));
var properties = member.GetType().GetProperties();
foreach (var keyValuePair in values)
foreach (var (key, value) in values)
{
var propertyInfo = properties.FirstOrDefault(x => x.Name == keyValuePair.Key);
var propertyInfo = properties.FirstOrDefault(x => x.Name == key);
if (propertyInfo == null) continue;
propertyInfo.SetValue(member, keyValuePair.Value);
var currentValue = propertyInfo.GetValue(member);
if(Equals(currentValue, value)) continue;
propertyInfo.SetValue(member, value);
}
}
}

Binary file not shown.

View File

@ -96,7 +96,7 @@ else
{
<ModalHeader>
<ModalTitle>Members of @SelectedSecurityGroup.CommonName group</ModalTitle>
<CloseButton Clicked="@HideModal"/>
<CloseButton Clicked="@(async () => await HideModalAsync(false))"/>
</ModalHeader>
<ModalBody>
<Row>
@ -135,7 +135,7 @@ else
{
<TableRow>
<TableRowHeader>@member.MemberId</TableRowHeader>
<TableRowCell>@member.AttachedMember.CommonName</TableRowCell>
<TableRowCell>@member.AttachedMember?.CommonName</TableRowCell>
<TableRowCell>
<Button Color="Color.Danger">Delete</Button>
</TableRowCell>
@ -148,7 +148,8 @@ else
</ModalBody>
<ModalFooter>
<Button Color="Color.Primary" Clicked="@HideModal">Close</Button>
<Button Color="Color.Primary" Clicked="@(async () => await HideModalAsync(true))">OK</Button>
<Button Color="Color.Primary" Clicked="@(async () => await HideModalAsync(false))">Cancel</Button>
</ModalFooter>
}
</ModalContent>

View File

@ -6,6 +6,7 @@ using Blazorise;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using UserService.DatabaseLayer.Repositories;
using UserService.Infrastructure;
using UserService.Infrastructure.DataModels;
namespace UserService.Pages
@ -103,11 +104,8 @@ namespace UserService.Pages
AttachedMember = SelectedMember
});
SelectedMember = default;
//await SecurityGroupsRepository.UpdateAsync(SelectedSecurityGroup).ConfigureAwait(false);
}
protected void OnButtonClicked(SecurityGroup securityGroup)
{
SelectedSecurityGroup = securityGroup;
@ -131,9 +129,9 @@ namespace UserService.Pages
public Member? SelectedMember { get; set; }
protected void HideModal()
protected async Task HideModalAsync(bool save)
{
if (save && SelectedSecurityGroup != null) await SecurityGroupsRepository.UpdateAsync(SelectedSecurityGroup).ConfigureAwait(false);
ModalRef.Hide();
}
}