fix issue

This commit is contained in:
Suphonchai Phoonsawat 2025-04-28 12:02:29 +07:00
parent 28544df284
commit ae2112f23a
3 changed files with 365 additions and 237 deletions

View file

@ -1,6 +1,4 @@
using System.Drawing;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using Amazon.S3.Model;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Responses.Leaves;
@ -12,6 +10,10 @@ using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Nest;
using System.Drawing;
using System.Net.Http.Headers;
using System.Net.Http.Json;
namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
{
@ -27,6 +29,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
private readonly EmailSenderService _emailSenderService;
private readonly IApplicationDBContext _appDbContext;
private readonly MinIOLeaveService _minIOService;
private readonly string URL = string.Empty;
@ -40,7 +43,8 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService,
IApplicationDBContext appDbContext) : base(dbContext, httpContextAccessor)
IApplicationDBContext appDbContext,
MinIOLeaveService minIOService) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
@ -51,6 +55,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
_appDbContext = appDbContext;
URL = (_configuration["API"]).Replace("/api/v1", "");
_minIOService = minIOService;
}
#endregion
@ -197,6 +202,53 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
#endregion
public async Task AddLeaveDocumentAsync(Guid id, LeaveDocument doc)
{
try
{
var req = await _dbContext.Set<LeaveRequest>().FirstOrDefaultAsync(x => x.Id == id);
req!.LeaveDocument.Add(doc);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task AddApproversAsync(Guid id, List<LeaveRequestApprover> approvers)
{
try
{
var req = await _dbContext.Set<LeaveRequest>().FirstOrDefaultAsync(x => x.Id == id);
req!.Approvers.AddRange(approvers);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task RemoveApproversAsync(Guid id, string type)
{
try
{
var data = await _dbContext.Set<LeaveRequestApprover>()
.Where(x => x.LeaveRequest.Id == id && x.ApproveType.ToUpper() == type.ToUpper())
.ToListAsync();
_dbContext.Set<LeaveRequestApprover>().RemoveRange(data);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<List<LeaveRequest>> GetLeaveRequestByYearAsync(int year)
{
var data = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
@ -289,7 +341,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
.Where(x => x.LeaveYear == year)
.Where(x => x.LeaveTypeId == leaveTypeId)
.FirstOrDefaultAsync();
var startFiscalDate = new DateTime(year - 1, 10, 1);