78 lines
2.8 KiB
C#
78 lines
2.8 KiB
C#
|
|
using _0_Framework.InfraStructure;
|
|
using AccountManagement.Application.Contracts.SubAccountPermissionSubtitle;
|
|
using AccountManagement.Domain.SubAccountAgg;
|
|
using AccountManagement.Domain.SubAccountPermissionSubtitle1Agg;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace AccountMangement.Infrastructure.EFCore.Repository
|
|
{
|
|
public class SubAccountPermissionSubtitle1Repository : RepositoryBase<long, SubAccountPermissionSubtitle1>,
|
|
ISubAccountPermissionSubtitle1Repository
|
|
{
|
|
private readonly AccountContext _context;
|
|
|
|
public SubAccountPermissionSubtitle1Repository(AccountContext context) : base(context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public List<SubAccountPermissionSubtitleViewModel> GetAllWithChildren()
|
|
{
|
|
return _context.SubAccountPermissionSubtitle1Collection.Include(x => x.Children)
|
|
.ThenInclude(x => x.Children)
|
|
.ThenInclude(x => x.Children).AsSplitQuery().Select(x => new SubAccountPermissionSubtitleViewModel
|
|
{
|
|
Id = x.id,
|
|
Code = x.Code,
|
|
Title = x.Title,
|
|
Children = x.Children.Select(y => new SubAccountPermissionSubtitleViewModel
|
|
{
|
|
Id = y.id,
|
|
Code = y.Code,
|
|
Title = y.Title,
|
|
Children = y.Children.Select(z => new SubAccountPermissionSubtitleViewModel
|
|
{
|
|
Id = z.id,
|
|
Code = z.Code,
|
|
Title = z.Title,
|
|
Children = z.Children.Select(w => new SubAccountPermissionSubtitleViewModel
|
|
{
|
|
Id = w.id,
|
|
Code = w.Code,
|
|
Title = w.Title,
|
|
}).OrderBy(w => w.Title).ToList()
|
|
}).OrderBy(z => z.Title).ToList(),
|
|
|
|
}).OrderBy(y => y.Title).ToList()
|
|
}).OrderBy(x => x.Title).AsNoTracking().ToList();
|
|
|
|
|
|
}
|
|
|
|
public List<int> GetAllPermissionCodes()
|
|
{
|
|
var data = GetAllWithChildren();
|
|
return Flatten(data);
|
|
|
|
}
|
|
|
|
public List<int> Flatten(List<SubAccountPermissionSubtitleViewModel> hierarchy)
|
|
{
|
|
var flatList = new List<int>();
|
|
foreach (var item in hierarchy)
|
|
{
|
|
flatList.Add(item.Code);
|
|
if (item.Children != null && item.Children.Any())
|
|
{
|
|
flatList.AddRange(Flatten(item.Children.ToList()));
|
|
}
|
|
}
|
|
|
|
return flatList;
|
|
}
|
|
}
|
|
}
|