From 6efeec3f1ff329465d7780b9ed6fa17bfa5961e7 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 16 Apr 2026 19:05:26 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20List=20=E0=B8=82=E0=B8=AD=E0=B8=87=E0=B8=81=E0=B8=B2?= =?UTF-8?q?=E0=B8=A3=E0=B9=80=E0=B8=88=E0=B9=89=E0=B8=AB=E0=B8=99=E0=B9=89?= =?UTF-8?q?=E0=B8=B2=E0=B8=97=E0=B8=B5=E0=B9=88=20=E0=B8=AA=E0=B9=88?= =?UTF-8?q?=E0=B8=87=20noti=20=E0=B8=82=E0=B8=AD=E0=B8=A2=E0=B8=81?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=B4=E0=B8=81=E0=B8=81=E0=B8=B2=E0=B8=A3?= =?UTF-8?q?=E0=B8=A5=E0=B8=B2=20#2432?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Domain/Shared/GlobalMessages.cs | 2 ++ .../Controllers/LeaveRequestController.cs | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/BMA.EHR.Domain/Shared/GlobalMessages.cs b/BMA.EHR.Domain/Shared/GlobalMessages.cs index 8746de95..a99dc3c9 100644 --- a/BMA.EHR.Domain/Shared/GlobalMessages.cs +++ b/BMA.EHR.Domain/Shared/GlobalMessages.cs @@ -8,6 +8,8 @@ public static readonly string DataNotFound = "ไม่พบข้อมูลในระบบ"; + public static readonly string ProfileNotFound = "ไม่พบข้อมูลในระบบทะเบียนประวัติ"; + public static readonly string NotAuthorized = "กรุณาเข้าสู่ระบบก่อนใช้งาน!"; public static readonly string ForbiddenAccess = "คุณไม่ได้รับอนุญาติให้เข้าใช้งาน!"; diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 7bc3b151..1252eef3 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -1876,6 +1876,12 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); } + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken); + if (profile == null) + { + return Error(GlobalMessages.ProfileNotFound, StatusCodes.Status404NotFound); + } + // change status to delete // แก้จาก DELETE เป็น DELETING ไว้ก่อน รอ approve ค่อยเปลี่ยนเป็น DELETE // data.LeaveStatus = "DELETE"; @@ -1929,6 +1935,28 @@ namespace BMA.EHR.Leave.Service.Controllers _appDbContext.Set().Add(noti1); } + // Get Officer List + var officers = await _userProfileRepository.GetOCStaffAsync(profile.Id, AccessToken); + var approverProfileIdList = approvers.Select(x => x.ProfileId).ToList(); + + if(officers != null && officers.Count > 0) + { + officers = officers.Where(x => !approverProfileIdList.Contains(x.ProfileId)).ToList(); + foreach (var officer in officers) + { + // Send Notification + var noti = new Notification + { + Body = $"คำร้องขอยกเลิกการลาของคุณ {data.FirstName} {data.LastName} รอรับการอนุมัติจากคุณ", + ReceiverUserId = officer.ProfileId, + Type = "", + Payload = $"{URL}/leave/detail/{id}", + }; + _appDbContext.Set().Add(noti); + } + await _appDbContext.SaveChangesAsync(); + } + return Success(); }