บันทึกการลาลงทะเบียนประวัติ

This commit is contained in:
Kittapath 2024-06-27 18:02:48 +07:00
parent 92e298c745
commit 8b10a65d2a

View file

@ -1,4 +1,6 @@
using System.Drawing; using System.Drawing;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging; using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.HR; using BMA.EHR.Domain.Models.HR;
@ -404,7 +406,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้"); throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้");
} }
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId,AccessToken); var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
if (profile == null) if (profile == null)
{ {
throw new Exception(GlobalMessages.DataNotFound); throw new Exception(GlobalMessages.DataNotFound);
@ -421,19 +423,38 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
// insert to profile leave // 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<ProfileLeave>().Add(profileLeave);
var _baseAPI = _configuration["API"];
var apiUrlSalary = $"{_baseAPI}/org/profile/leave";
using (var client = new HttpClient())
{ {
DateStartLeave = rawData.LeaveStartDate, client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
DateEndLeave = rawData.LeaveEndDate, var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
TotalLeave = rawData.LeaveTotal, profileId = profile.Id,
Status = "approve", leaveTypeId = leaveType?.Id ?? null,
Reason = rawData.LeaveDetail, dateLeaveStart = rawData.LeaveStartDate,
dateLeaveEnd = rawData.LeaveEndDate,
ProfileId = profile.Id, // change from profile object to id leaveDays = 0,//หน้า fe ไม่ได้ใช้
TypeLeave = leaveType leaveCount = 0,//หน้า fe ไม่ได้ใช้
}; totalLeave = rawData.LeaveTotal,
_appDbContext.Set<ProfileLeave>().Add(profileLeave); status = "approve",
reason = rawData.LeaveDetail,
});
// var _result = await _res.Content.ReadAsStringAsync();
}
await _appDbContext.SaveChangesAsync(); await _appDbContext.SaveChangesAsync();
// insert to process timestamp // insert to process timestamp