Refactor LeaveProcessJobStatusRepository to update API endpoint paths and comment out JSON file writing logic

This commit is contained in:
Suphonchai Phoonsawat 2026-03-31 11:28:12 +07:00
parent a50153f32c
commit 932d5e75c7

View file

@ -420,28 +420,28 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
}
// Write employees to JSON file
var fileName = $"employees_{DateTime.Now:yyyyMMdd_HHmmss}.txt";
var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Exports", fileName);
// var fileName = $"employees_{DateTime.Now:yyyyMMdd_HHmmss}.txt";
// var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Exports", fileName);
// Ensure directory exists
var directory = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
// // Ensure directory exists
// var directory = Path.GetDirectoryName(filePath);
// if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
// {
// Directory.CreateDirectory(directory);
// }
var jsonOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
// var jsonOptions = new JsonSerializerOptions
// {
// WriteIndented = true,
// Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
// };
var jsonContent = JsonSerializer.Serialize(employees, jsonOptions);
await File.WriteAllTextAsync(filePath, jsonContent);
// var jsonContent = JsonSerializer.Serialize(employees, jsonOptions);
// await File.WriteAllTextAsync(filePath, jsonContent);
}
//call api
var apiPath = $"{_configuration["API"]}/org/profile/absent-late/batch";
var apiPath = $"{_configuration["API"]}/org/unauthorize/profile/absent-late/batch";
var apiKey = _configuration["API_KEY"];
var body = new
{
@ -702,41 +702,41 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
}
// Write employees to JSON file
var fileName = $"employees_{DateTime.Now:yyyyMMdd_HHmmss}.txt";
var filePath = Path.Combine(_env.ContentRootPath, "Exports", fileName);
// var fileName = $"employees_{DateTime.Now:yyyyMMdd_HHmmss}.txt";
// var filePath = Path.Combine(_env.ContentRootPath, "Exports", fileName);
// Ensure directory exists
var directory = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
// // Ensure directory exists
// var directory = Path.GetDirectoryName(filePath);
// if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
// {
// Directory.CreateDirectory(directory);
// }
var jsonOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
// var jsonOptions = new JsonSerializerOptions
// {
// WriteIndented = true,
// Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
// };
var jsonContent = JsonSerializer.Serialize(employees, jsonOptions);
Console.WriteLine($"Writing file to: {filePath}");
await File.WriteAllTextAsync(filePath, jsonContent);
Console.WriteLine($"File written successfully: {fileName}");
// var jsonContent = JsonSerializer.Serialize(employees, jsonOptions);
// Console.WriteLine($"Writing file to: {filePath}");
// await File.WriteAllTextAsync(filePath, jsonContent);
// Console.WriteLine($"File written successfully: {fileName}");
}
//call api
// var apiPath = $"{_configuration["API"]}/org/profile-employee/absent-late/batch";
// var apiKey = _configuration["API_KEY"];
// var body = new
// {
// records = employees
// };
// call api
var apiPath = $"{_configuration["API"]}/org/unauthorize/profile-employee/absent-late/batch";
var apiKey = _configuration["API_KEY"];
var body = new
{
records = employees
};
// var apiResult = await PostExternalAPIAsync(apiPath, AccessToken ?? "", body, apiKey);
// if(apiResult == "")
// {
// throw new Exception($"เรียก API {apiPath} ไม่สำเร็จ");
// }
var apiResult = await PostExternalAPIAsync(apiPath, AccessToken ?? "", body, apiKey);
if(apiResult == "")
{
throw new Exception($"เรียก API {apiPath} ไม่สำเร็จ");
}
}