insert profile leave

This commit is contained in:
Suphonchai Phoonsawat 2024-01-10 09:52:59 +07:00
parent eb5f39a561
commit 6d62d357a6
2 changed files with 44 additions and 0 deletions

View file

@ -1,5 +1,6 @@
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Leave.Commons;
using BMA.EHR.Domain.Models.Leave.Requests;
using BMA.EHR.Domain.Models.Notifications;
@ -297,6 +298,24 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
// TODO: remove วันลา
var leaveType = await _appDbContext.Set<TypeLeave>()
.FirstOrDefaultAsync(x => x.Name == rawData.Type.Name);
// insert to profile leave
var profileLeave = await _appDbContext.Set<ProfileLeave>()
.Where(x => x.TypeLeave.Id == leaveType.Id)
.Where(x => x.DateStartLeave == rawData.LeaveStartDate && x.DateEndLeave == rawData.LeaveEndDate)
.FirstOrDefaultAsync();
if (profileLeave != null)
{
_appDbContext.Set<ProfileLeave>().Remove(profileLeave);
await _appDbContext.SaveChangesAsync();
}
// insert into process timestamp
// Send Noti
var noti = new Notification
{
@ -382,6 +401,29 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
await UpdateAsync(rawData);
var leaveType = await _appDbContext.Set<TypeLeave>()
.FirstOrDefaultAsync(x => x.Name == rawData.Type.Name);
// insert to profile leave
var profileLeave = new ProfileLeave
{
DateStartLeave = rawData.LeaveStartDate,
DateEndLeave = rawData.LeaveEndDate,
TotalLeave = rawData.LeaveTotal,
Status = "approve",
Reason = rawData.LeaveDetail,
Profile = profile,
TypeLeave = leaveType
};
_appDbContext.Set<ProfileLeave>().Add(profileLeave);
await _appDbContext.SaveChangesAsync();
// insert to process timestamp
// Send Noti
var noti = new Notification
{

View file

@ -29,6 +29,8 @@ namespace BMA.EHR.Application.Repositories
#region " Methods "
public async Task<Profile?> GetProfileByKeycloakIdAsync(Guid keycloakId)
{
try