Get Receiver for Command C-PM-01, C-PM-02
This commit is contained in:
parent
ec39bf1505
commit
6253d8d2ab
2 changed files with 119 additions and 24 deletions
|
|
@ -71,10 +71,11 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
switch (command.CommandType.CommandCode.Trim().ToUpper())
|
||||
{
|
||||
case "C-PM-01":
|
||||
case "C-PM-02":
|
||||
case "C-PM-03":
|
||||
result = await GetReceiver01Async(command);
|
||||
break;
|
||||
case "C-PM-02":
|
||||
result = await GetReceiver02Async(command);
|
||||
break;
|
||||
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
||||
}
|
||||
|
||||
|
|
@ -82,9 +83,9 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-01
|
||||
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CommandReceiver>> GetReceiver01Async(Command command)
|
||||
{
|
||||
|
|
@ -97,13 +98,15 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
||||
.Include(x => x.Command)
|
||||
.ThenInclude(x => x.CommandType)
|
||||
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM"))
|
||||
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper().StartsWith("C-PM-01"))
|
||||
.Where(x => x.Command.Id != command.Id)
|
||||
.Select(x => x.CitizenId)
|
||||
.ToListAsync();
|
||||
|
||||
// 2. Query
|
||||
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
||||
.Include(x => x.Placement)
|
||||
.ThenInclude(x => x.PlacementType)
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
|
|
@ -111,6 +114,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
||||
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
||||
.Where(x => x.Draft! == true)
|
||||
.Where(x => x.Placement!.PlacementType!.Name == "สอบแข่งขัน")
|
||||
.OrderBy(x => x.ExamNumber)
|
||||
.ToListAsync();
|
||||
|
||||
|
|
@ -118,19 +122,20 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
var seq = 1;
|
||||
foreach (var item in appointPeople)
|
||||
{
|
||||
|
||||
var receiver = new CommandReceiver
|
||||
if (!(await CheckIsActiveOfficer(item.CitizenId!)))
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = item.CitizenId!,
|
||||
Prefix = item.Prefix!.Name,
|
||||
FirstName = item.Firstname!,
|
||||
LastName = item.Lastname!,
|
||||
RefPlacementProfileId = item.Id
|
||||
};
|
||||
seq++;
|
||||
|
||||
result.Add(receiver);
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = item.CitizenId!,
|
||||
Prefix = item.Prefix!.Name,
|
||||
FirstName = item.Firstname!,
|
||||
LastName = item.Lastname!,
|
||||
RefPlacementProfileId = item.Id
|
||||
};
|
||||
seq++;
|
||||
result.Add(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
@ -141,6 +146,72 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
|
||||
/// </summary>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task<List<CommandReceiver>> GetReceiver02Async(Command command)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new List<CommandReceiver>();
|
||||
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
|
||||
|
||||
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
|
||||
var otherCommandReceivers = await _dbContext.Set<CommandReceiver>()
|
||||
.Include(x => x.Command)
|
||||
.ThenInclude(x => x.CommandType)
|
||||
.Where(x => x.Command.CommandType.CommandCode.Trim().ToUpper() == "C-PM-02")
|
||||
.Where(x => x.Command.Id != command.Id)
|
||||
.Select(x => x.CitizenId)
|
||||
.ToListAsync();
|
||||
|
||||
// 2. Query
|
||||
var appointPeople = await _dbContext.Set<PlacementProfile>()
|
||||
.Include(x => x.Placement)
|
||||
.ThenInclude(x => x.PlacementType)
|
||||
.Include(x => x.Prefix)
|
||||
.Include(x => x.OrganizationPosition)
|
||||
.ThenInclude(x => x!.Organization)
|
||||
//.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
|
||||
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
|
||||
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
|
||||
.Where(x => x.Draft! == true)
|
||||
.Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน")
|
||||
.OrderBy(x => x.ExamNumber)
|
||||
.ToListAsync();
|
||||
|
||||
// 3. Create new Record
|
||||
var seq = 1;
|
||||
foreach (var item in appointPeople)
|
||||
{
|
||||
if (!(await CheckIsActiveOfficer(item.CitizenId!)))
|
||||
{
|
||||
var receiver = new CommandReceiver
|
||||
{
|
||||
Sequence = seq,
|
||||
CitizenId = item.CitizenId!,
|
||||
Prefix = item.Prefix!.Name,
|
||||
FirstName = item.Firstname!,
|
||||
LastName = item.Lastname!,
|
||||
RefPlacementProfileId = item.Id
|
||||
};
|
||||
seq++;
|
||||
|
||||
result.Add(receiver);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Execute and Deploy "
|
||||
|
|
@ -151,15 +222,20 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
{
|
||||
case "C-PM-01":
|
||||
case "C-PM-02":
|
||||
case "C-PM-03":
|
||||
await ExecuteCommand01Async(command);
|
||||
await ExecuteCommand01_02Async(command);
|
||||
break;
|
||||
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private async Task ExecuteCommand01Async(Command command)
|
||||
/// <summary>
|
||||
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้,
|
||||
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
|
||||
/// </summary>
|
||||
/// <param name="command">object ของรายการคำสั่ง</param>
|
||||
/// <returns></returns>
|
||||
private async Task ExecuteCommand01_02Async(Command command)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using Amazon.S3.Model.Internal.MarshallTransformations;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Domain.Models.Base;
|
||||
using BMA.EHR.Domain.Models.HR;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Security.Claims;
|
||||
|
|
@ -13,7 +15,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly DbSet<T> _dbSet;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
|
@ -24,7 +26,7 @@ namespace BMA.EHR.Application.Repositories
|
|||
_dbContext = dbContext;
|
||||
_dbSet = _dbContext.Set<T>();
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -35,12 +37,29 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
protected string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<bool> CheckIsActiveOfficer(string citizenId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var pf = await _dbContext.Set<Profile>()
|
||||
.Where(x => x.CitizenId == citizenId)
|
||||
.Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return pf != null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<IReadOnlyList<T>> GetAllAsync()
|
||||
{
|
||||
return await _dbSet.ToListAsync();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue