Add Org and Approver Api
This commit is contained in:
parent
3c11d1b5a1
commit
5c5c85a120
3 changed files with 126 additions and 3 deletions
|
|
@ -24,6 +24,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly OrganizationCommonRepository _organizationCommonRepository;
|
||||
private readonly UserProfileRepository _userProfileRepository;
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -31,11 +32,28 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
public CommandRepository(IApplicationDBContext dbContext,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
OrganizationCommonRepository organizationCommonRepository) : base(dbContext, httpContextAccessor)
|
||||
OrganizationCommonRepository organizationCommonRepository,
|
||||
UserProfileRepository userProfileRepository) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_organizationCommonRepository = organizationCommonRepository;
|
||||
_userProfileRepository = userProfileRepository;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Properties "
|
||||
|
||||
protected Guid UserOrganizationId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (UserId != null || UserId != "")
|
||||
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
|
||||
else
|
||||
return Guid.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -490,6 +508,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
.Include(x => x.Receivers)
|
||||
.Include(x => x.CommandStatus)
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
|
||||
}
|
||||
|
||||
public override async Task<IReadOnlyList<Command>> GetAllAsync()
|
||||
|
|
@ -1188,13 +1207,13 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
|
||||
#endregion
|
||||
|
||||
#region " Organization and Approver "
|
||||
|
||||
public async Task<Guid> GetRootOcIdAsync(Guid ocId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
|
||||
//.Include(x => x.OrganizationAgency)
|
||||
//.Include(x => x.OrganizationGovernmentAgency)
|
||||
.FirstOrDefaultAsync(o => o.Id == ocId);
|
||||
|
||||
if (data == null)
|
||||
|
|
@ -1208,6 +1227,95 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<KeyValueItemResponse>> GetCommandOrgAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new List<KeyValueItemResponse>();
|
||||
ret.Add(new KeyValueItemResponse
|
||||
{
|
||||
Id = Guid.Empty,
|
||||
Name = "กรุงเทพมหานคร"
|
||||
});
|
||||
|
||||
var rootOcId = await GetRootOcIdAsync(UserOrganizationId);
|
||||
|
||||
var oc = await _dbContext.Set<OrganizationEntity>().FirstOrDefaultAsync(x => x.Id == rootOcId);
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<KeyValueItemResponse>> GetOrgApproverAsync(Guid ocId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ocId == Guid.Empty)
|
||||
return new List<KeyValueItemResponse>() { new KeyValueItemResponse { Id = Guid.Empty, Name = "ปลัดกรุงเทพมหานคร" } };
|
||||
else
|
||||
{
|
||||
//var ret = new List<KeyValueItemResponse>();
|
||||
var oc = await _dbContext.Set<OrganizationEntity>().Include(x => x.Parent).FirstOrDefaultAsync(x => x.Id == ocId);
|
||||
|
||||
var profilePosition = await _dbContext.Set<ProfilePosition>()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.PositionMaster)
|
||||
.Where(x => x.OrganizationPosition!.Organization!.Id == ocId &&
|
||||
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
|
||||
.Select(x => new KeyValueItemResponse
|
||||
{
|
||||
Id = x.Profile!.Id,
|
||||
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
if (profilePosition.Count > 0)
|
||||
{
|
||||
return profilePosition;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (oc != null && oc.Parent != null)
|
||||
{
|
||||
var parentProfilePosition = await _dbContext.Set<ProfilePosition>()
|
||||
.Include(x => x.Profile)
|
||||
.ThenInclude(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.PositionMaster)
|
||||
.Where(x => x.OrganizationPosition!.Organization!.Id == oc.Parent.Id &&
|
||||
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
|
||||
.Select(x => new KeyValueItemResponse
|
||||
{
|
||||
Id = x.Profile!.Id,
|
||||
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}"
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
return parentProfilePosition;
|
||||
}
|
||||
else
|
||||
return new List<KeyValueItemResponse>();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly DbSet<T> _dbSet;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
_dbContext = dbContext;
|
||||
_dbSet = _dbContext.Set<T>();
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -34,6 +36,10 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
protected string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
|
|
|||
9
BMA.EHR.Application/Responses/KeyValueItemResponse.cs
Normal file
9
BMA.EHR.Application/Responses/KeyValueItemResponse.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace BMA.EHR.Application.Responses
|
||||
{
|
||||
public class KeyValueItemResponse
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.Empty;
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue