From 7c2a4c0280a8d6de9f39db155da76d673bce5cd3 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Mon, 18 Dec 2023 16:03:45 +0700 Subject: [PATCH] =?UTF-8?q?fix=20LV1=5F003=20-=20=E0=B8=A5=E0=B8=9A?= =?UTF-8?q?=E0=B8=A3=E0=B8=AD=E0=B8=9A=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=9B?= =?UTF-8?q?=E0=B8=8F=E0=B8=B4=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=87?= =?UTF-8?q?=E0=B8=B2=E0=B8=99=20(ADMIN)#3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Leaves/TimeAttendants/UserDutyTimeRepository.cs | 9 +++++++++ BMA.EHR.Leave.Service/Controllers/LeaveController.cs | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs index 9c7a1053..00f7aa55 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs @@ -112,6 +112,15 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants return data; } + public async Task GetFirstInUseRound(Guid id) + { + var data = await _dbContext.Set() + .Where(x => x.DutyTimeId == id) + .FirstOrDefaultAsync(); + + return data; + } + #endregion } diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs index 6ac14c11..4e4fab39 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs @@ -277,7 +277,8 @@ namespace BMA.EHR.Leave.Service.Controllers } else { - if (oldData.IsActive || oldData.IsDefault) + var inUseRound = _userDutyTimeRepository.GetFirstInUseRound(oldData.Id); + if (inUseRound != null || oldData.IsActive || oldData.IsDefault) { throw new Exception("ไม่สามารถลบรอบการปฏิบัติงานที่ยังใช้งานอยู่ได้"); }