diff --git a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs index 5e94c1e4..e580b00a 100644 --- a/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveBeginningController.cs @@ -580,32 +580,37 @@ namespace BMA.EHR.Leave.Service.Controllers [HttpPut("schedule/update-dna")] [AllowAnonymous] - public async Task> ScheduleUpdateDnaAsync([FromBody] ScheduleUpdateDnaDto req) + public async Task> ScheduleUpdateDnaAsync([FromBody] List 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)