เพิ่ม link สำนักตาม keycloak
This commit is contained in:
parent
0b5c7038a6
commit
86a6ab9514
10 changed files with 712 additions and 289 deletions
|
|
@ -38,6 +38,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
#region " Fields "
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly MetadataDbContext _contextMetadata;
|
||||
private readonly MinIOService _minioService;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly DisableService _disableService;
|
||||
|
|
@ -50,6 +51,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
#region " Constructor and Destructor "
|
||||
|
||||
public DisableController(ApplicationDbContext context,
|
||||
MetadataDbContext contextMetadata,
|
||||
MinIOService minioService,
|
||||
IWebHostEnvironment webHostEnvironment,
|
||||
DisableService disableService,
|
||||
|
|
@ -57,6 +59,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
ILogger<DisableController> logger)
|
||||
{
|
||||
_context = context;
|
||||
_contextMetadata = contextMetadata;
|
||||
_minioService = minioService;
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
_disableService = disableService;
|
||||
|
|
@ -175,6 +178,32 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
throw;
|
||||
}
|
||||
}
|
||||
private List<Guid?> GetAllIdByRoot(Guid id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ret = new List<Guid?>();
|
||||
|
||||
var oc = _contextMetadata.Organizations.FirstOrDefault(x => x.Id == id && x.IsActive);
|
||||
if (oc != null)
|
||||
ret.Add(oc.Id);
|
||||
|
||||
var child = _contextMetadata.Organizations.AsQueryable().Where(x => x.ParentId == id && x.IsActive).ToList();
|
||||
if (child.Any())
|
||||
{
|
||||
foreach (var item in child)
|
||||
{
|
||||
ret.AddRange(GetAllIdByRoot(item.Id));
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -659,11 +688,48 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers
|
|||
ImportDate = x.CreatedAt.Date.ToThaiShortDate(),
|
||||
ScoreCount = x.ScoreImport.Scores.Count(),
|
||||
|
||||
}
|
||||
},
|
||||
x.CreatedUserId,
|
||||
})
|
||||
.ToListAsync();
|
||||
var profileOrganizations = await _contextMetadata.ProfileOrganizations.AsQueryable()
|
||||
.ToListAsync();
|
||||
var _periodExams = (from x in data
|
||||
join po in profileOrganizations on Guid.Parse(x.CreatedUserId) equals po?.UserId into poGroup
|
||||
from po in poGroup.DefaultIfEmpty()
|
||||
select new
|
||||
{
|
||||
x.Id,
|
||||
x.Year,
|
||||
x.Name,
|
||||
x.Round,
|
||||
x.ImportDate,
|
||||
x.ExamCount,
|
||||
x.CreatedUserId,
|
||||
OcId = po == null ? null : po.OrganizationId,
|
||||
}).AsQueryable()
|
||||
.ToList();
|
||||
|
||||
return Success(data);
|
||||
var roles = _httpContextAccessor?.HttpContext?.User?.FindAll(ClaimTypes.Role)?.Select(c => c.Value).ToList();
|
||||
if (!roles.Contains("head"))
|
||||
{
|
||||
var criteria = new List<Guid?>();
|
||||
var profileOrganization = await _contextMetadata.ProfileOrganizations.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.UserId == Guid.Parse(UserId));
|
||||
|
||||
if (profileOrganization == null)
|
||||
throw new Exception(GlobalMessages.OrganizationNotFound);
|
||||
|
||||
var ocId = _contextMetadata.Organizations.AsQueryable()
|
||||
.FirstOrDefault(x => x.Id == profileOrganization.OrganizationId);
|
||||
if (ocId == null)
|
||||
throw new Exception(GlobalMessages.OrganizationNotFound);
|
||||
criteria = GetAllIdByRoot(ocId.Id);
|
||||
if (criteria.Any())
|
||||
_periodExams = _periodExams.Where(x => x.CreatedUserId == UserId || criteria.Contains(x.OcId == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.OcId)).ToList();
|
||||
}
|
||||
|
||||
return Success(_periodExams);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue