บันทึกผู้อนุมัติการลา โโยแปลง 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,

View file

@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
using BMA.EHR.Domain.Models.Base;
using Newtonsoft.Json;
using System.ComponentModel.DataAnnotations;
namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
{
@ -99,6 +101,30 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
public string? CoupleDaySumTotalHistory { get; set; }
public string? Approvers { get; set; } = string.Empty;
}
public class LeaveRequestApproverDto
{
[JsonProperty("seq")]
public int Seq { get; set; } = 0;
[JsonProperty("prefix")]
public string Prefix { get; set; } = string.Empty;
[JsonProperty("firstName")]
public string FirstName { get; set; } = string.Empty;
[JsonProperty("lastName")]
public string LastName { get; set; } = string.Empty;
[JsonProperty("positionName")]
public string PositionName { get; set; } = string.Empty;
[JsonProperty("profileId")]
public Guid ProfileId { get; set; } = Guid.Empty;
[JsonProperty("keycloakId")]
public Guid KeycloakId { get; set; } = Guid.Empty;
}
}