บันทึกผู้อนุมัติการลา โโยแปลง json ที่มาจาก FormData

This commit is contained in:
Suphonchai Phoonsawat 2025-04-17 10:58:09 +07:00
parent 885478f672
commit 28b573bfb8
2 changed files with 54 additions and 3 deletions

View file

@ -20,6 +20,7 @@ using Swashbuckle.AspNetCore.Annotations;
using System.Net.Http.Headers;
using System.Security.Claims;
using System.Security.Policy;
using System.Text.Json.Nodes;
namespace BMA.EHR.Leave.Service.Controllers
{
@ -170,7 +171,7 @@ namespace BMA.EHR.Leave.Service.Controllers
var leaveRequest = new LeaveRequest
{
Type = leaveType,
LeaveSubTypeName = req.LeaveSubTypeName,
LeaveRange = req.LeaveRange,
LeaveStartDate = req.LeaveStartDate,
@ -366,6 +367,30 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
leaveRequest.OrganizationName = userOc;
if (req.Approvers != null && req.Approvers != "")
{
//var jsonString = System.Text.Json.JsonSerializer.Deserialize<string>(req.Approvers ?? "");
//var fixedJson = req.Approvers.Replace("\\\"", "\"");
var approvers = JsonConvert.DeserializeObject<List<LeaveRequestApproverDto>>(req.Approvers);
if (approver != null)
{
foreach (var r in approvers!)
{
leaveRequest.Approvers.Add(new LeaveRequestApprover
{
Seq = r.Seq,
Prefix = r.Prefix,
FirstName = r.FirstName,
LastName = r.LastName,
PositionName = r.PositionName,
ProfileId = r.ProfileId,
KeycloakId = r.KeycloakId,
ApproveStatus = "PENDING",
});
}
}
}
// save to database
@ -1989,7 +2014,7 @@ namespace BMA.EHR.Leave.Service.Controllers
// เปลี่ยนมาอ่านจากฐานข้อมูลแทน read_db
Dear = rawData.Dear ?? "",
CommanderPosition = rawData.CommanderPosition ?? "",
CommanderPosition = rawData.CommanderPosition ?? "",
PositionName = rawData.PositionName ?? "",
PositionLevelName = rawData.PositionLevelName ?? "",
OrganizationName = orgName,