Added FxCop and get Organization Unit selection running

This commit is contained in:
2020-08-13 22:53:44 +02:00
parent fc5c6d0ce7
commit 23da5583fd
17 changed files with 84 additions and 47 deletions

View File

@ -12,7 +12,7 @@ namespace UserService.DatabaseLayer.Repository
{
public class BaseRepository<T> where T : Node
{
protected readonly Func<UserServiceDbContext, DbSet<T>> Context;
protected Func<UserServiceDbContext, DbSet<T>> Context { get; }
protected BaseRepository(Func<UserServiceDbContext, DbSet<T>> context)
{
@ -22,27 +22,27 @@ namespace UserService.DatabaseLayer.Repository
public virtual async Task<IReadOnlyList<T>> GetAllAsync(Expression<Func<T, bool>>? predicate = null, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
return await Context(db).Include(x => x.Parent).WhereOrDefault(predicate).ToListAsync(token);
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)
{
await using var db = new UserServiceDbContext();
return await Context(db).FirstOrDefaultAsync(predicate, token);
return await Context(db).FirstOrDefaultAsync(predicate, token).ConfigureAwait(false);
}
public async Task AddAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
await Context(db).AddAsync(@entity, token);
await db.SaveChangesAsync(token);
await Context(db).AddAsync(@entity, token).ConfigureAwait(false);
await db.SaveChangesAsync(token).ConfigureAwait(false);
}
public async Task<bool> UpdateAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
Context(db).Update(entity);
var items= await db.SaveChangesAsync(token);
var items= await db.SaveChangesAsync(token).ConfigureAwait(false);
return items > 0;
}
@ -50,7 +50,7 @@ namespace UserService.DatabaseLayer.Repository
{
await using var db = new UserServiceDbContext();
Context(db).Remove(entity);
await db.SaveChangesAsync(token);
await db.SaveChangesAsync(token).ConfigureAwait(false);
}
}
}