feature: save members of security group

This commit is contained in:
2020-09-11 22:41:21 +02:00
parent 31ef9bf45b
commit baec3160af
6 changed files with 52 additions and 30 deletions

View File

@ -30,7 +30,7 @@ namespace UserService.DatabaseLayer.DataModels
{
if (modelBuilder == null) throw new ArgumentNullException(nameof(modelBuilder));
modelBuilder.Entity<MembersMember>()
.HasKey(bc => new { bc.MemberId, AttachedMemberId = bc.AttachedMemberId });
.HasKey(bc => new { bc.MemberId, bc.AttachedMemberId });
modelBuilder.Entity<MembersMember>()
.HasOne(bc => bc.AttachedMember)
.WithMany(b => b!.MemberOf)

View File

@ -26,10 +26,10 @@ namespace UserService.DatabaseLayer.Repositories
return await Context(db).Include(x => x.Parent).WhereOrDefault(predicate).ToListAsync(token).ConfigureAwait(false);
}
public async Task<T?> GetAsync(Expression<Func<T, bool>> predicate, CancellationToken token = default)
public virtual async Task<T?> GetAsync(Expression<Func<T, bool>> predicate, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
return await Context(db).FirstOrDefaultAsync(predicate, token).ConfigureAwait(false);
return await Context(db).Include(x => x.Parent).FirstOrDefaultAsync(predicate, token).ConfigureAwait(false);
}
public async Task AddAsync(T entity, CancellationToken token = default)

View File

@ -1,4 +1,11 @@
using UserService.Infrastructure.DataModels;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using UserService.DatabaseLayer.DataModels;
using UserService.Infrastructure.DataModels;
namespace UserService.DatabaseLayer.Repositories
{
@ -7,5 +14,12 @@ namespace UserService.DatabaseLayer.Repositories
public SecurityGroupsRepository() : base(x => x.SecurityGroups)
{
}
public override async Task<IReadOnlyList<SecurityGroup>> GetAllAsync(Expression<Func<SecurityGroup, bool>>? predicate = null, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
return await Context(db).Include(x => x.Parent).WhereOrDefault(predicate).ToListAsync(token).ConfigureAwait(false);
}
}
}