From 8b10a65d2a2d979e70d7117080fdb5af17665df7 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 27 Jun 2024 18:02:48 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B8=A5=E0=B8=B2=E0=B8=A5?= =?UTF-8?q?=E0=B8=87=E0=B8=97=E0=B8=B0=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2?= =?UTF-8?q?=E0=B8=99=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95?= =?UTF-8?q?=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LeaveRequests/LeaveRequestRepository.cs | 47 ++++++++++++++----- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 4a9731f3..578c700e 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -1,4 +1,6 @@ using System.Drawing; +using System.Net.Http.Headers; +using System.Net.Http.Json; using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Messaging; using BMA.EHR.Domain.Models.HR; @@ -404,7 +406,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้"); } - var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId,AccessToken); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken); if (profile == null) { throw new Exception(GlobalMessages.DataNotFound); @@ -421,19 +423,38 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests // insert to profile leave - var profileLeave = new ProfileLeave + // var profileLeave = new ProfileLeave + // { + // DateStartLeave = rawData.LeaveStartDate, + // DateEndLeave = rawData.LeaveEndDate, + + // TotalLeave = rawData.LeaveTotal, + // Status = "approve", + // Reason = rawData.LeaveDetail, + + // ProfileId = profile.Id, // change from profile object to id + // TypeLeave = leaveType + // }; + // _appDbContext.Set().Add(profileLeave); + var _baseAPI = _configuration["API"]; + var apiUrlSalary = $"{_baseAPI}/org/profile/leave"; + using (var client = new HttpClient()) { - DateStartLeave = rawData.LeaveStartDate, - DateEndLeave = rawData.LeaveEndDate, - - TotalLeave = rawData.LeaveTotal, - Status = "approve", - Reason = rawData.LeaveDetail, - - ProfileId = profile.Id, // change from profile object to id - TypeLeave = leaveType - }; - _appDbContext.Set().Add(profileLeave); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", "")); + var _res = await client.PostAsJsonAsync(apiUrlSalary, new + { + profileId = profile.Id, + leaveTypeId = leaveType?.Id ?? null, + dateLeaveStart = rawData.LeaveStartDate, + dateLeaveEnd = rawData.LeaveEndDate, + leaveDays = 0,//หน้า fe ไม่ได้ใช้ + leaveCount = 0,//หน้า fe ไม่ได้ใช้ + totalLeave = rawData.LeaveTotal, + status = "approve", + reason = rawData.LeaveDetail, + }); + // var _result = await _res.Content.ReadAsStringAsync(); + } await _appDbContext.SaveChangesAsync(); // insert to process timestamp