fix ccode

This commit is contained in:
Suphonchai Phoonsawat 2025-05-08 22:19:12 +07:00
parent 496917c34c
commit 4cc57322c0
4 changed files with 47 additions and 8 deletions

View file

@ -1,15 +1,16 @@
using Amazon.S3.Model.Internal.MarshallTransformations;
using Amazon.Runtime.Internal.Endpoints.StandardLibrary;
using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Base;
using BMA.EHR.Domain.Models.HR;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json.Linq;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Text;
using Microsoft.Extensions.Configuration;
namespace BMA.EHR.Application.Repositories
{
@ -76,13 +77,45 @@ namespace BMA.EHR.Application.Repositories
}
}
protected async Task<string> SendExternalAPIAsync(HttpMethod method, string apiPath, string accessToken, object? body, string apiKey)
{
try
{
// สร้าง request message
var request = new HttpRequestMessage(method, apiPath);
var json = JsonConvert.SerializeObject(body);
request.Content = new StringContent(json, Encoding.UTF8, "application/json");
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", apiKey);
var _res = await client.SendAsync(request);
if (_res.IsSuccessStatusCode)
{
var _result = await _res.Content.ReadAsStringAsync();
return _result;
}
return string.Empty;
}
}
catch
{
throw;
}
}
protected async Task<string> PostExternalAPIAsync(string apiPath, string accessToken, object? body, string apiKey)
{
try
{
var json = JsonConvert.SerializeObject(body);
var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json");
stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
//stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
using (var client = new HttpClient())
{

View file

@ -7728,7 +7728,7 @@ namespace BMA.EHR.Application.Repositories
if (period != null && period.InsigniaEmployees != null)
{
allEmployeeProfileByRoot =
(await _userProfileRepository.GetEmployeeProfileByPositionAsync(ocId, period.InsigniaEmployees.Select(x => x.RefId), AccessToken));
(await _userProfileRepository.GetEmployeeProfileByPositionAsync(ocId, period.InsigniaEmployees.Select(x => x.RefId!.ValueOrBlank()).ToArray(), AccessToken));
}
var type_coin = allOfficerProfilesByRoot.Count() > 0 ? await GetCoinCandidate(periodId, ocId, allOfficerProfilesByRoot) : new List<InsigniaResultSet>();

View file

@ -12,6 +12,7 @@ using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.Reflection.Emit;
using System.Security.Cryptography;
using System.Text;
namespace BMA.EHR.Application.Repositories
{
@ -130,7 +131,7 @@ namespace BMA.EHR.Application.Repositories
}
}
public async Task<List<GetProfileByRootIdDto>> GetEmployeeProfileByPositionAsync(Guid rootId, dynamic empPosId, string? accessToken)
public async Task<List<GetProfileByRootIdDto>> GetEmployeeProfileByPositionAsync(Guid rootId, string[] empPosId, string? accessToken)
{
try
{
@ -143,6 +144,11 @@ namespace BMA.EHR.Application.Repositories
empPosId
};
//var bodyJson = JsonConvert.SerializeObject(bodyRaw);
// สร้าง HTTP content
//var body = new StringContent(bodyJson, Encoding.UTF8, "application/json");
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)