From 7d3ec6c74e8d71a4b4858068982b51bcbb74320d Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 18 Feb 2026 16:34:35 +0700 Subject: [PATCH] Refactor ScheduleUpdateLeaveBeginningAsync to use ScheduleEditLeaveBeginningDto and remove unused profile checks --- .../Controllers/LeaveBeginningController.cs | 40 +++++++++---------- .../LeaveBeginnings/EditLeaveBeginningDto.cs | 16 ++++++++ 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs index 245176da..28f88302 100644 --- a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs @@ -500,15 +500,15 @@ namespace BMA.EHR.Leave.Service.Controllers [HttpPut("schedule")] [AllowAnonymous] - public async Task> ScheduleUpdateLeaveBeginningAsync([FromBody] EditLeaveBeginningDto req) + public async Task> ScheduleUpdateLeaveBeginningAsync([FromBody] ScheduleEditLeaveBeginningDto req) { try { - var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken); - if(profile == null) - { - return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound); - } + // var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken); + // if(profile == null) + // { + // return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound); + // } // check duplicate var oldData = await _context.LeaveBeginnings.FirstOrDefaultAsync(x => x.ProfileId == req.ProfileId && x.LeaveTypeId == req.LeaveTypeId @@ -520,23 +520,23 @@ namespace BMA.EHR.Leave.Service.Controllers oldData.LeaveTypeId = req.LeaveTypeId; oldData.LeaveYear = req.LeaveYear; oldData.LeaveDays = req.LeaveDays; - oldData.LeaveDaysUsed = req.LeaveDaysUsed; - oldData.LeaveCount = req.LeaveCount; - oldData.BeginningLeaveDays = req.BeginningLeaveDays; - oldData.BeginningLeaveCount = req.BeginningLeaveCount; + // oldData.LeaveDaysUsed = req.LeaveDaysUsed; + // oldData.LeaveCount = req.LeaveCount; + // oldData.BeginningLeaveDays = req.BeginningLeaveDays; + // oldData.BeginningLeaveCount = req.BeginningLeaveCount; - oldData.ProfileId = req.ProfileId; - oldData.Prefix = profile.Prefix; - oldData.FirstName = profile.FirstName; - oldData.LastName = profile.LastName; - oldData.RootDnaId = profile.RootDnaId; - oldData.Child1DnaId = profile.Child1DnaId; - oldData.Child2DnaId = profile.Child2DnaId; - oldData.Child3DnaId = profile.Child3DnaId; - oldData.Child4DnaId = profile.Child4DnaId; + // oldData.ProfileId = req.ProfileId; + // oldData.Prefix = profile.Prefix; + // oldData.FirstName = profile.FirstName; + // oldData.LastName = profile.LastName; + // oldData.RootDnaId = profile.RootDnaId; + // oldData.Child1DnaId = profile.Child1DnaId; + // oldData.Child2DnaId = profile.Child2DnaId; + // oldData.Child3DnaId = profile.Child3DnaId; + // oldData.Child4DnaId = profile.Child4DnaId; oldData.LastUpdateUserId = ""; - oldData.LastUpdateFullName = FullName ?? ""; + oldData.LastUpdateFullName = "System"; oldData.LastUpdatedAt = DateTime.Now; await _leaveBeginningRepository.UpdateAsync(oldData); diff --git a/BMA.EHR.Leave/DTOs/LeaveBeginnings/EditLeaveBeginningDto.cs b/BMA.EHR.Leave/DTOs/LeaveBeginnings/EditLeaveBeginningDto.cs index d4a2661f..fe0c433f 100644 --- a/BMA.EHR.Leave/DTOs/LeaveBeginnings/EditLeaveBeginningDto.cs +++ b/BMA.EHR.Leave/DTOs/LeaveBeginnings/EditLeaveBeginningDto.cs @@ -29,4 +29,20 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings [Comment("จำนวนครั้งที่ลายกมา")] public int BeginningLeaveCount { get; set; } = 0; } + + + public class ScheduleEditLeaveBeginningDto + { + [Required] + public Guid ProfileId { get; set; } = Guid.Empty; + + [Required] + public Guid LeaveTypeId { get; set; } = Guid.Empty; + + [Required, Comment("ปีงบประมาณ")] + public int LeaveYear { get; set; } = 0; + + [Required, Comment("จำนวนวันลายกมา")] + public double LeaveDays { get; set; } = 0.0; + } }