diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index acb10e8b..d9e612e0 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -2554,6 +2554,59 @@ namespace BMA.EHR.Leave.Service.Controllers } + [HttpPost("round/multiple")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> CreateChangeRoundMultipleAsync([FromBody] List reqs) + { + var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_WORK_ROUND_EDIT"); + var jsonData = JsonConvert.DeserializeObject(getPermission); + if (jsonData["status"]?.ToString() != "200") + { + return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); + } + var currentDate = DateTime.Now.Date; + + foreach(var req in reqs) + { + var profile = await _userProfileRepository.GetProfileByProfileIdAsync(req.ProfileId, AccessToken); + if (profile == null) + { + return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); + } + + if (req.EffectiveDate.Date < currentDate) + { + return Error(new Exception($"กำหนดรอบลงเวลาของ {profile.FirstName} {profile.LastName} ผิดพลาด เนื่องจากวันที่มีผลต้องมากกว่าหรือเท่ากับวันที่ปัจจุบัน({currentDate.ToString("yyyy-MM-dd")})"), StatusCodes.Status400BadRequest); + } + + var old = await _userDutyTimeRepository.GetExist(req.ProfileId, req.EffectiveDate); + + if (old != null) + { + return Error(new Exception($"กำหนดรอบลงเวลาของ {profile.FirstName} {profile.LastName} ผิดพลาด เนื่องจากมีการกำหนดรอบการทำงานในวันที่นี้ไว้แล้ว"), StatusCodes.Status400BadRequest); + } + + var data = new UserDutyTime + { + ProfileId = req.ProfileId, + DutyTimeId = req.RoundId, + EffectiveDate = req.EffectiveDate, + Remark = req.Remark, + + RootDnaId = profile.RootDnaId, + Child1DnaId = profile.Child1DnaId, + Child2DnaId = profile.Child2DnaId, + Child3DnaId = profile.Child3DnaId, + Child4DnaId = profile.Child4DnaId, + }; + + await _userDutyTimeRepository.AddAsync(data); + } + return Success(); + } + /// /// LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN) ///