Add CreateChangeRoundMultipleAsync method for batch processing of duty time changes #1555
All checks were successful
All checks were successful
This commit is contained in:
parent
7e0f0485fd
commit
23bbd9791e
1 changed files with 53 additions and 0 deletions
|
|
@ -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<ActionResult<ResponseObject>> CreateChangeRoundMultipleAsync([FromBody] List<CreateChangeRoundDto> reqs)
|
||||
{
|
||||
var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_WORK_ROUND_EDIT");
|
||||
var jsonData = JsonConvert.DeserializeObject<JObject>(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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LV1_015 - ประวัติการเปลี่ยนรอบการลงเวลา (ADMIN)
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue