102 lines
3.1 KiB
C#
102 lines
3.1 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Responses;
|
|
using BMA.EHR.Domain.Models.Organizations;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BMA.EHR.Application.Repositories
|
|
{
|
|
public class OrganizationCommonRepository
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destuctor "
|
|
|
|
public OrganizationCommonRepository(IApplicationDBContext dbContext,
|
|
IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_dbContext = dbContext;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
public string GetOrganizationNameFullPath(Guid id, bool showRoot = false, bool descending = false)
|
|
{
|
|
try
|
|
{
|
|
var ocList = GetOCWithFullPath(id, showRoot);
|
|
if (descending)
|
|
ocList = ocList.OrderBy(x => x.Order).ToList();
|
|
|
|
var ret = String.Empty;
|
|
foreach (var oc in ocList)
|
|
{
|
|
ret = oc.Name + " " + ret;
|
|
}
|
|
if (ret.Length > 2)
|
|
ret = ret.Substring(0, ret.Length - 1);
|
|
|
|
return ret;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<OrganizationItem> GetOCWithFullPath(Guid id, bool showRoot = false)
|
|
{
|
|
try
|
|
{
|
|
var ocList = new List<OrganizationItem>();
|
|
|
|
var ocData = _dbContext.Set<OrganizationEntity>()
|
|
.Include(x => x.OrganizationOrganization)
|
|
.Include(x => x.Parent)
|
|
.Select(x => new
|
|
{
|
|
Id = x.Id,
|
|
Name = x.OrganizationOrganization!.Name,
|
|
ParentId = x.Parent!.Id
|
|
})
|
|
.FirstOrDefault(x => x.Id == id);
|
|
|
|
if (ocData != null)
|
|
{
|
|
ocList.Add(new OrganizationItem { Id = ocData.Id, Name = ocData.Name });
|
|
|
|
//if (!showRoot)
|
|
//{
|
|
// if (!oc.IsRoot)
|
|
// ocList.Add(new OrganizationItem { Id = oc.OCId, Name = oc.OrganizationName });
|
|
//}
|
|
//else
|
|
// ocList.Add(new OrganizationItem { Id = oc.OCId, Name = oc.OrganizationName });
|
|
|
|
if (ocData.ParentId != null)
|
|
{
|
|
ocList.AddRange(GetOCWithFullPath(ocData.ParentId, showRoot));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return ocList;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|