Refactor ScheduleUpdateDnaAsync to handle a list of ScheduleUpdateDnaDto and streamline profile updates #2341
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m59s
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m59s
This commit is contained in:
parent
f866435897
commit
4650f7a2ab
1 changed files with 24 additions and 19 deletions
|
|
@ -580,32 +580,37 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
[HttpPut("schedule/update-dna")]
|
||||
[AllowAnonymous]
|
||||
public async Task<ActionResult<ResponseObject>> ScheduleUpdateDnaAsync([FromBody] ScheduleUpdateDnaDto req)
|
||||
public async Task<ActionResult<ResponseObject>> ScheduleUpdateDnaAsync([FromBody] List<ScheduleUpdateDnaDto> req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(req.ProfileId, AccessToken);
|
||||
if(profile == null)
|
||||
foreach(var item in req)
|
||||
{
|
||||
return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
||||
}
|
||||
// check duplicate
|
||||
var oldData = await _context.LeaveBeginnings.Where(x => x.ProfileId == req.ProfileId).ToListAsync();
|
||||
|
||||
foreach(var item in oldData)
|
||||
{
|
||||
item.RootDnaId = profile.RootDnaId;
|
||||
item.Child1DnaId = profile.Child1DnaId;
|
||||
item.Child2DnaId = profile.Child2DnaId;
|
||||
item.Child3DnaId = profile.Child3DnaId;
|
||||
item.Child4DnaId = profile.Child4DnaId;
|
||||
// var profile = await _userProfileRepository.GetProfileByProfileIdNoAuthAsync(item.ProfileId, AccessToken);
|
||||
// if(profile == null)
|
||||
// {
|
||||
// return Error("ไม่พบข้อมูลข้าราชการหรือลูกจ้าง", StatusCodes.Status404NotFound);
|
||||
// }
|
||||
// check duplicate
|
||||
var oldData = await _context.LeaveBeginnings.Where(x => x.ProfileId == item.ProfileId).ToListAsync();
|
||||
|
||||
foreach(var o in oldData)
|
||||
{
|
||||
o.RootDnaId = item.RootDnaId;
|
||||
o.Child1DnaId = item.Child1DnaId;
|
||||
o.Child2DnaId = item.Child2DnaId;
|
||||
o.Child3DnaId = item.Child3DnaId;
|
||||
o.Child4DnaId = item.Child4DnaId;
|
||||
|
||||
item.LastUpdateUserId = "";
|
||||
item.LastUpdateFullName = "System";
|
||||
item.LastUpdatedAt = DateTime.Now;
|
||||
o.LastUpdateUserId = "";
|
||||
o.LastUpdateFullName = "System";
|
||||
o.LastUpdatedAt = DateTime.Now;
|
||||
|
||||
await _leaveBeginningRepository.UpdateAsync(item);
|
||||
await _leaveBeginningRepository.UpdateAsync(o);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Success();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue