report รายชื่อผู้สมัครสอบคัดเลือกผู้พิการ (generate ตรง)
This commit is contained in:
parent
7a5f135e1f
commit
125dd59348
2 changed files with 190 additions and 10 deletions
|
|
@ -165,19 +165,66 @@ namespace BMA.EHR.Recurit.Exam.Service.Core
|
|||
// อ่านข้อมูลจาก Response หลังจากที่ได้ถูกส่งออกไป
|
||||
memoryStream.Seek(0, SeekOrigin.Begin);
|
||||
var responseBody = new StreamReader(memoryStream).ReadToEnd();
|
||||
if (responseBody != "")
|
||||
responseBodyJson = JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(responseBody), new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true, Converters = { new DateTimeFixConverter() } });
|
||||
//if (responseBody != "")
|
||||
// responseBodyJson = JsonSerializer.Serialize(JsonSerializer.Deserialize<object>(responseBody), new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping, WriteIndented = true, Converters = { new DateTimeFixConverter() } });
|
||||
|
||||
var json = JsonSerializer.Deserialize<JsonElement>(responseBody);
|
||||
if (json.ValueKind == JsonValueKind.Array)
|
||||
//var json = JsonSerializer.Deserialize<JsonElement>(responseBody);
|
||||
//if (json.ValueKind == JsonValueKind.Array)
|
||||
//{
|
||||
// message = "success";
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// if (json.TryGetProperty("message", out var messageElement))
|
||||
// {
|
||||
// message = messageElement.GetString();
|
||||
// }
|
||||
//}
|
||||
|
||||
if (!string.IsNullOrEmpty(responseBody))
|
||||
{
|
||||
message = "success";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (json.TryGetProperty("message", out var messageElement))
|
||||
var contentType = context.Response.ContentType ?? "";
|
||||
|
||||
if (contentType.Equals(
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
message = messageElement.GetString();
|
||||
// Excel
|
||||
responseBodyJson = $"Excel file (Length={memoryStream.Length} bytes)";
|
||||
message = "success";
|
||||
}
|
||||
else if (contentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
// JSON
|
||||
try
|
||||
{
|
||||
responseBodyJson = JsonSerializer.Serialize(
|
||||
JsonSerializer.Deserialize<object>(responseBody),
|
||||
new JsonSerializerOptions
|
||||
{
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
WriteIndented = true,
|
||||
Converters = { new DateTimeFixConverter() }
|
||||
});
|
||||
|
||||
var json = JsonSerializer.Deserialize<JsonElement>(responseBody);
|
||||
if (json.ValueKind == JsonValueKind.Array)
|
||||
message = "success";
|
||||
else if (json.TryGetProperty("message", out var messageElement))
|
||||
message = messageElement.GetString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// fallback ถ้า deserialize ไม่ได้
|
||||
responseBodyJson = responseBody;
|
||||
message = "success";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// plain text / HTML / binary อื่น
|
||||
responseBodyJson = responseBody;
|
||||
message = "success";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue