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("ไม่สามารถลบรอบการปฏิบัติงานที่ยังใช้งานอยู่ได้"); }