Working in migration to linq2SQL

This commit is contained in:
2020-09-28 21:23:11 +02:00
parent 552e9cc6df
commit 9bf37f5799
17 changed files with 194 additions and 876 deletions

View File

@ -1,51 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using UserService.DatabaseLayer.DataModels;
using UserService.Infrastructure.DataModels;
using DataModels;
namespace UserService.DatabaseLayer.Repositories
{
public class OrganizationUnitsRepository : BaseRepository<OrganizationUnit>, IOrganizationUnitsRepository
public class OrganizationUnitsRepository : IOrganizationUnitsRepository
{
public OrganizationUnitsRepository() : base(x => x.OrganizationUnits)
/// <inheritdoc />
public async Task<IReadOnlyList<OrganizationUnit>> GetAllAsync(Expression<Func<OrganizationUnit, bool>>? predicate = null, CancellationToken token = default)
{
throw new NotImplementedException();
}
/// <inheritdoc cref="GetAllAsync" />
public override async Task<IReadOnlyList<OrganizationUnit>> GetAllAsync(
Expression<Func<OrganizationUnit, bool>>? predicate = null, CancellationToken token = default)
/// <inheritdoc />
public async Task<OrganizationUnit?> GetAsync(Expression<Func<OrganizationUnit, bool>> predicate, CancellationToken token = default)
{
await using var db = new UserServiceDbContext();
var rootOus = await Context(db)
.Include(x => x.Parent)
.WhereOrDefault(predicate)
.ToListAsync(token).ConfigureAwait(false);
throw new NotImplementedException();
}
IEnumerable<OrganizationUnit> Rec(Node node)
{
if (!(node is OrganizationUnit organizationUnit)) yield break;
yield return organizationUnit;
foreach (var ouChild in rootOus.Where(x => x.ParentId != null && x.ParentId == organizationUnit.Id))
{
foreach (var unit in Rec(ouChild))
{
yield return unit;
}
}
}
/// <inheritdoc />
public async Task AddAsync(OrganizationUnit entity, CancellationToken token = default)
{
throw new NotImplementedException();
}
var result = new List<OrganizationUnit>();
foreach (var ou in rootOus.Where(x => x.ParentId is null))
{
result.AddRange(Rec(ou));
}
/// <inheritdoc />
public async Task<bool> UpdateAsync(OrganizationUnit entity, CancellationToken token = default)
{
throw new NotImplementedException();
}
return result;
/// <inheritdoc />
public async Task DeleteAsync(OrganizationUnit entity, CancellationToken token = default)
{
throw new NotImplementedException();
}
}
}