Added Blazorise gui framework

This commit is contained in:
2020-08-03 22:15:25 +02:00
parent 61b32841bd
commit 17f3274abc
14 changed files with 290 additions and 238 deletions

View File

@ -1,8 +1,8 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -12,43 +12,46 @@ namespace UserService.DatabaseLayer.Repository
{
public class BaseRepository<T> where T : Node
{
protected readonly Func<UserServiceDbContext, DbSet<T>> _context;
protected readonly Func<UserServiceDbContext, DbSet<T>> Context;
protected BaseRepository(Func<UserServiceDbContext, DbSet<T>> context)
{
_context = context;
Context = context;
}
public virtual async Task<IReadOnlyList<T>> GetAllAsync(CancellationToken token = default)
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).ToListAsync(token);
IQueryable<T> queryable = Context(db).Include(x => x.Parent);
if(queryable != null) queryable = queryable.Where(predicate);
return await queryable.ToListAsync(token);
}
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);
}
public async Task AddAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
await _context(db).AddAsync(@entity, token);
await Context(db).AddAsync(@entity, token);
await db.SaveChangesAsync(token);
}
public async Task UpdateAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
_context(db).Update(entity);
Context(db).Update(entity);
await db.SaveChangesAsync(token);
}
public async Task DeleteAsync(T entity, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
_context(db).Remove(entity);
Context(db).Remove(entity);
await db.SaveChangesAsync(token);
}
}

View File

@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading;
@ -9,7 +10,7 @@ namespace UserService.DatabaseLayer.Repository
{
public interface IRepository<T> where T : Node
{
Task<IReadOnlyList<T>> GetAllAsync(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 AddAsync(T entity, CancellationToken token = default);
Task UpdateAsync(T entity, CancellationToken token = default);

View File

@ -23,7 +23,7 @@ namespace UserService.DatabaseLayer.Repository
await using var db = new UserServiceDbContext();
var result = new List<OrganizationUnit>();
var rootOus = await _context(db)
var rootOus = await Context(db)
.Include(x => x.Parent)
.ToListAsync(token);