diff --git a/Models/Placement/PlacementProfile.cs b/Models/Placement/PlacementProfile.cs index d517793..47a6b1c 100644 --- a/Models/Placement/PlacementProfile.cs +++ b/Models/Placement/PlacementProfile.cs @@ -246,6 +246,8 @@ namespace BMA.EHR.Domain.Models.Placement [Comment("หมายเหตุแนวนอน")] public string? RemarkHorizontal { get; set; } + [Comment("profileId")] + public string? profileId { get; set; } public virtual List PlacementCertificates { get; set; } = new List(); public virtual List PlacementEducations { get; set; } = new List(); } diff --git a/Services/RecruitService.cs b/Services/RecruitService.cs index b58ac17..1f7971e 100644 --- a/Services/RecruitService.cs +++ b/Services/RecruitService.cs @@ -10,6 +10,8 @@ using BMA.EHR.MetaData.Service.Models; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Recurit.Service.Data; using System.Security.Claims; +using System.Net.Http.Headers; +using Newtonsoft.Json; namespace BMA.EHR.Recruit.Service.Services { @@ -19,16 +21,19 @@ namespace BMA.EHR.Recruit.Service.Services private readonly MetadataDbContext _contextMetadata; private readonly MinIOService _minIOService; private readonly IHttpContextAccessor _httpContextAccessor; + private readonly IConfiguration _configuration; public RecruitService(ApplicationDbContext context, MetadataDbContext contextMetadata, IHttpContextAccessor httpContextAccessor, - MinIOService minIOService) + MinIOService minIOService, + IConfiguration configuration) { _context = context; _contextMetadata = contextMetadata; _minIOService = minIOService; _httpContextAccessor = httpContextAccessor; + _configuration = configuration; } #region " Properties " @@ -36,6 +41,7 @@ namespace BMA.EHR.Recruit.Service.Services private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; + private string? token => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"]; #endregion @@ -204,6 +210,27 @@ namespace BMA.EHR.Recruit.Service.Services .ToListAsync(); foreach (var candidate in candidates) { + var IsOfficer = false; + dynamic org = null; + var apiUrl = $"{_configuration["API"]}org/profile/citizenid/position/{candidate.CitizenId}"; + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); + var _res = await client.SendAsync(_req); + var _result = await _res.Content.ReadAsStringAsync(); + + org = JsonConvert.DeserializeObject(_result); + + if (org == null || org.result == null) + { + IsOfficer = false; + } + else + { + IsOfficer = true; + } + } var Address = candidate.Addresses.FirstOrDefault() == null ? null : $"{candidate.Addresses.FirstOrDefault().Address}"; var Moo = candidate.Addresses.FirstOrDefault() == null ? null : $" หมู่ {candidate.Addresses.FirstOrDefault().Moo}"; var Soi = candidate.Addresses.FirstOrDefault() == null ? null : $" ซอย {candidate.Addresses.FirstOrDefault().Soi}"; @@ -308,6 +335,8 @@ namespace BMA.EHR.Recruit.Service.Services LastUpdatedAt = DateTime.Now, LastUpdateUserId = UserId ?? "", LastUpdateFullName = FullName ?? "", + IsOfficer = IsOfficer, + profileId = org == null || org.result == null ? null : org.result.profileId, }; await _contextMetadata.PlacementProfiles.AddAsync(placementProfile); diff --git a/appsettings.json b/appsettings.json index cae10dc..a15f409 100644 --- a/appsettings.json +++ b/appsettings.json @@ -31,5 +31,6 @@ "AccessKey": "ZQOGEjHxDesiVIHR", "SecretKey": "vKTpcxY0Wjjp775aDwNn1q6VWJu8EFb6", "BucketName": "bma-recruit" - } + }, + "API": "https://bma-ehr.frappet.synology.me/api/v1/" } \ No newline at end of file