Refactor ScheduleUpdateLeaveBeginningAsync to use ScheduleEditLeaveBeginningDto and remove unused profile checks
This commit is contained in:
parent
1b7bdd82e6
commit
7d3ec6c74e
2 changed files with 36 additions and 20 deletions
|
|
@ -500,15 +500,15 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
|
|
||||||
[HttpPut("schedule")]
|
[HttpPut("schedule")]
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
public async Task<ActionResult<ResponseObject>> ScheduleUpdateLeaveBeginningAsync([FromBody] EditLeaveBeginningDto req)
|
public async Task<ActionResult<ResponseObject>> ScheduleUpdateLeaveBeginningAsync([FromBody] ScheduleEditLeaveBeginningDto req)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken);
|
// var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken);
|
||||||
if(profile == null)
|
// if(profile == null)
|
||||||
{
|
// {
|
||||||
return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
// return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
||||||
}
|
// }
|
||||||
// check duplicate
|
// check duplicate
|
||||||
var oldData = await _context.LeaveBeginnings.FirstOrDefaultAsync(x => x.ProfileId == req.ProfileId
|
var oldData = await _context.LeaveBeginnings.FirstOrDefaultAsync(x => x.ProfileId == req.ProfileId
|
||||||
&& x.LeaveTypeId == req.LeaveTypeId
|
&& x.LeaveTypeId == req.LeaveTypeId
|
||||||
|
|
@ -520,23 +520,23 @@ namespace BMA.EHR.Leave.Service.Controllers
|
||||||
oldData.LeaveTypeId = req.LeaveTypeId;
|
oldData.LeaveTypeId = req.LeaveTypeId;
|
||||||
oldData.LeaveYear = req.LeaveYear;
|
oldData.LeaveYear = req.LeaveYear;
|
||||||
oldData.LeaveDays = req.LeaveDays;
|
oldData.LeaveDays = req.LeaveDays;
|
||||||
oldData.LeaveDaysUsed = req.LeaveDaysUsed;
|
// oldData.LeaveDaysUsed = req.LeaveDaysUsed;
|
||||||
oldData.LeaveCount = req.LeaveCount;
|
// oldData.LeaveCount = req.LeaveCount;
|
||||||
oldData.BeginningLeaveDays = req.BeginningLeaveDays;
|
// oldData.BeginningLeaveDays = req.BeginningLeaveDays;
|
||||||
oldData.BeginningLeaveCount = req.BeginningLeaveCount;
|
// oldData.BeginningLeaveCount = req.BeginningLeaveCount;
|
||||||
|
|
||||||
oldData.ProfileId = req.ProfileId;
|
// oldData.ProfileId = req.ProfileId;
|
||||||
oldData.Prefix = profile.Prefix;
|
// oldData.Prefix = profile.Prefix;
|
||||||
oldData.FirstName = profile.FirstName;
|
// oldData.FirstName = profile.FirstName;
|
||||||
oldData.LastName = profile.LastName;
|
// oldData.LastName = profile.LastName;
|
||||||
oldData.RootDnaId = profile.RootDnaId;
|
// oldData.RootDnaId = profile.RootDnaId;
|
||||||
oldData.Child1DnaId = profile.Child1DnaId;
|
// oldData.Child1DnaId = profile.Child1DnaId;
|
||||||
oldData.Child2DnaId = profile.Child2DnaId;
|
// oldData.Child2DnaId = profile.Child2DnaId;
|
||||||
oldData.Child3DnaId = profile.Child3DnaId;
|
// oldData.Child3DnaId = profile.Child3DnaId;
|
||||||
oldData.Child4DnaId = profile.Child4DnaId;
|
// oldData.Child4DnaId = profile.Child4DnaId;
|
||||||
|
|
||||||
oldData.LastUpdateUserId = "";
|
oldData.LastUpdateUserId = "";
|
||||||
oldData.LastUpdateFullName = FullName ?? "";
|
oldData.LastUpdateFullName = "System";
|
||||||
oldData.LastUpdatedAt = DateTime.Now;
|
oldData.LastUpdatedAt = DateTime.Now;
|
||||||
|
|
||||||
await _leaveBeginningRepository.UpdateAsync(oldData);
|
await _leaveBeginningRepository.UpdateAsync(oldData);
|
||||||
|
|
|
||||||
|
|
@ -29,4 +29,20 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings
|
||||||
[Comment("จำนวนครั้งที่ลายกมา")]
|
[Comment("จำนวนครั้งที่ลายกมา")]
|
||||||
public int BeginningLeaveCount { get; set; } = 0;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue