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