92 lines
4.9 KiB
C#
92 lines
4.9 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BMA.EHR.Application.Repositories
|
|
{
|
|
public class RetirementRepository : GenericRepository<Guid, RetirementPeriod>
|
|
{
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
public RetirementRepository(IApplicationDBContext dbContext,
|
|
NotificationRepository repositoryNoti,
|
|
IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
|
{
|
|
_dbContext = dbContext;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_repositoryNoti = repositoryNoti;
|
|
}
|
|
|
|
//ปลดออก
|
|
public async Task NotifyDischarge()
|
|
{
|
|
var cronjobNotis = await _dbContext.Set<RetirementDischarge>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
|
.AsQueryable()
|
|
.ToListAsync();
|
|
foreach (var cronjobNoti in cronjobNotis)
|
|
{
|
|
cronjobNoti.Profile.IsLeave = true;
|
|
cronjobNoti.Profile.LeaveReason = "DISCHARGE";
|
|
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
|
// await _repositoryNoti.PushNotificationAsync(
|
|
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
|
// );
|
|
}
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
//ไล่ออก
|
|
public async Task NotifyExpulsion()
|
|
{
|
|
var cronjobNotis = await _dbContext.Set<RetirementExpulsion>()
|
|
.Include(x => x.Profile)
|
|
.ThenInclude(x => x.Prefix)
|
|
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
|
.AsQueryable()
|
|
.ToListAsync();
|
|
foreach (var cronjobNoti in cronjobNotis)
|
|
{
|
|
cronjobNoti.Profile.IsLeave = true;
|
|
cronjobNoti.Profile.LeaveReason = "DISMISS";
|
|
cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
|
// await _repositoryNoti.PushNotificationAsync(
|
|
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
|
// );
|
|
}
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
|
|
//ให้ออก
|
|
public async Task NotifyOut()
|
|
{
|
|
var cronjobNotis = await _dbContext.Set<RetirementOut>()
|
|
//.Include(x => x.Profile)
|
|
//.ThenInclude(x => x.Prefix)
|
|
.Where(x => x.Date != null && x.Date.Value.Date == DateTime.Now.Date)
|
|
.AsQueryable()
|
|
.ToListAsync();
|
|
foreach (var cronjobNoti in cronjobNotis)
|
|
{
|
|
//cronjobNoti.Profile.IsLeave = true;
|
|
//cronjobNoti.Profile.LeaveReason = "LAYOFF";
|
|
//cronjobNoti.Profile.LeaveDate = DateTime.Now;
|
|
// await _repositoryNoti.PushNotificationAsync(
|
|
// Guid.Parse("08db721d-ada0-4e64-89d3-7584a893d8b8"),
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}",
|
|
// $"แจ้งเตือนการปลดออกของ {cronjobNoti.Profile.Prefix?.Name}{cronjobNoti.Profile.FirstName} {cronjobNoti.Profile.LastName}"
|
|
// );
|
|
}
|
|
await _dbContext.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|