Added very nice DataGrid control
This commit is contained in:
@ -0,0 +1,50 @@
|
||||
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;
|
||||
|
||||
namespace UserService.DatabaseLayer.Repository
|
||||
{
|
||||
public class OrganizationUnitsRepository : BaseRepository<OrganizationUnit>, IOrganizationUnitsRepository
|
||||
{
|
||||
public OrganizationUnitsRepository() : base(x => x.OrganizationUnits)
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="GetAllAsync" />
|
||||
public override async Task<IReadOnlyList<OrganizationUnit>> GetAllAsync(
|
||||
Expression<Func<OrganizationUnit, bool>>? predicate = null, CancellationToken token = default)
|
||||
{
|
||||
await using var db = new UserServiceDbContext();
|
||||
var result = new List<OrganizationUnit>();
|
||||
var rootOus = await Context(db)
|
||||
.Include(x => x.Parent)
|
||||
.WhereOrDefault(predicate)
|
||||
.ToListAsync(cancellationToken: token);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var ou in rootOus.Where(x => x.ParentId is null))
|
||||
{
|
||||
result.AddRange(Rec(ou));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user