hrms-api-backend/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs

11452 lines
656 KiB
C#

using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Messaging;
using BMA.EHR.Application.Requests.Commands;
using BMA.EHR.Application.Responses;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.Commands.Core;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.Leave.Commons;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Notifications;
using BMA.EHR.Domain.Models.OrganizationEmployee;
using BMA.EHR.Domain.Models.Organizations;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Models.Retirement;
using BMA.EHR.Domain.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Net.Http.Json;
using Command = BMA.EHR.Domain.Models.Commands.Core.Command;
using Profile = BMA.EHR.Domain.Models.HR.Profile;
namespace BMA.EHR.Application.Repositories.Commands
{
public class CommandRepository : GenericRepository<Guid, Command>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly OrganizationCommonRepository _organizationCommonRepository;
private readonly UserProfileRepository _userProfileRepository;
private readonly IConfiguration _configuration;
private readonly EmailSenderService _emailSenderService;
#endregion
#region " Constructor and Destuctor "
public CommandRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor,
OrganizationCommonRepository organizationCommonRepository,
UserProfileRepository userProfileRepository,
IConfiguration configuration,
EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_organizationCommonRepository = organizationCommonRepository;
_userProfileRepository = userProfileRepository;
_configuration = configuration;
_emailSenderService = emailSenderService;
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken);
else
return Guid.Empty;
}
}
#endregion
#region " Methods "
public void SendMail()
{
_emailSenderService.SendMail("Test Send Email", "ทดสอบส่งเมล์", "suphonchai.ph@gmail.com");
}
#region " Private "
#region " List Receiver "
public async Task<List<CommandReceiver>> GetReceiverForByCommndTypeAsync(Command command, string token = "")
{
var result = new List<CommandReceiver>();
switch (command.CommandType.CommandCode.Trim().ToUpper())
{
case "C-PM-01":
result = await GetReceiver01Async(command);
break;
case "C-PM-02":
result = await GetReceiver02Async(command);
break;
case "C-PM-03":
result = await GetReceiver03Async(command);
break;
case "C-PM-04":
result = await GetReceiver04Async(command);
break;
case "C-PM-39":
result = await GetReceiver39Async(command);
break;
case "C-PM-05":
result = await GetReceiver05Async(command);
break;
case "C-PM-06":
result = await GetReceiver06Async(command);
break;
case "C-PM-07":
result = await GetReceiver07Async(command);
break;
case "C-PM-08":
result = await GetReceiver08Async(command);
break;
case "C-PM-09":
result = await GetReceiver09Async(command);
break;
case "C-PM-10":
result = await GetReceiver10Async(command);
break;
case "C-PM-11":
result = await GetReceiver11Async(command, token);
break;
case "C-PM-12":
result = await GetReceiver12Async(command, token);
break;
case "C-PM-13":
result = await GetReceiver13Async(command);
break;
case "C-PM-14":
result = await GetReceiver14Async(command);
break;
case "C-PM-15":
result = await GetReceiver15Async(command);
break;
case "C-PM-16":
result = await GetReceiver16Async(command);
break;
case "C-PM-17":
result = await GetReceiver17Async(command);
break;
case "C-PM-18":
result = await GetReceiver18Async(command);
break;
case "C-PM-19":
result = await GetReceiver19Async(command, token);
break;
case "C-PM-20":
result = await GetReceiver20Async(command, token);
break;
case "C-PM-21":
result = await GetReceiver21Async(command, token);
break;
case "C-PM-22":
result = await GetReceiver22Async(command);
break;
case "C-PM-23":
result = await GetReceiver23Async(command);
break;
case "C-PM-24":
result = await GetReceiver24Async(command);
break;
case "C-PM-25":
result = await GetReceiver25Async(command, token);
break;
case "C-PM-26":
result = await GetReceiver26Async(command, token);
break;
case "C-PM-27":
result = await GetReceiver27Async(command, token);
break;
case "C-PM-28":
result = await GetReceiver28Async(command, token);
break;
case "C-PM-29":
result = await GetReceiver29Async(command, token);
break;
case "C-PM-30":
result = await GetReceiver30Async(command, token);
break;
case "C-PM-31":
result = await GetReceiver31Async(command, token);
break;
case "C-PM-32":
result = await GetReceiver32Async(command, token);
break;
case "C-PM-33":
result = await GetReceiver33Async(command, token);
break;
case "C-PM-34":
result = await GetReceiver34Async(command, token);
break;
case "C-PM-35":
result = await GetReceiver35Async(command, token);
break;
case "C-PM-36":
result = await GetReceiver36Async(command, token);
break;
case "C-PM-37":
result = await GetReceiver37Async(command, token);
break;
case "C-PM-38":
result = await GetReceiver38Async(command, token);
break;
case "C-PM-40":
result = await GetReceiver40Async(command, token);
break;
case "C-PM-41":
result = await GetReceiver41Async(command);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
}
return result;
}
/// <summary>
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver01Async(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().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)
.Where(x => x.Placement.Id == command.Placement.Id)
.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 == "สอบแข่งขัน")
.Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED")
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <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)
.Where(x => x.Placement.Id == command.Placement.Id)
.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 != "สอบแข่งขัน")
.Where(x => x.typeCommand.Trim().ToUpper() == "APPOINTED")
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver03Async(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-03")
.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)
.Where(x => x.Placement.Id == command.Placement.Id)
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.typeCommand.Trim().ToUpper() == "APPOINT")
.Where(x => x.Draft! == true)
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver04Async(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-04")
.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)
.Where(x => x.Placement.Id == command.Placement.Id)
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.typeCommand.Trim().ToUpper() == "MOVE")
.Where(x => x.Draft! == true)
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-39 - คำสั่งเลื่อน : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver39Async(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-39")
.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)
.Where(x => x.Placement.Id == command.Placement.Id)
.Where(x => !otherCommandReceivers.Contains(x.CitizenId!))
.Where(x => x.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN")
.Where(x => x.typeCommand.Trim().ToUpper() == "SLIP")
.Where(x => x.Draft! == true)
.OrderBy(x => x.ExamNumber)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId == null ? "" : item.CitizenId,
Prefix = item.Prefix == null ? "" : item.Prefix,
FirstName = item.Firstname == null ? "" : item.Firstname,
LastName = item.Lastname == null ? "" : item.Lastname,
RefPlacementProfileId = item.Id,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-05 - คำสั่งแต่งตั้ง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver05Async(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-05")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-06 - คำสั่งเลื่อน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver06Async(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-06")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-07 - คำสั่งย้าย
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver07Async(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-07")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver08Async(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-08")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementOther>()
.Include(x => x.CommandType)
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.Where(x => x.CommandType!.Id == command.CommandType!.Id)
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver09Async(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-09")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementOther>()
.Include(x => x.CommandType)
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.Where(x => x.CommandType!.Id == command.CommandType!.Id)
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver10Async(Command command)
{
try
{
var result = new List<CommandReceiver>();
var seq = 1;
// เอาชื่อของกรรมการ ไปหาจากทะเบียนประวัติ
var p1 = (await _dbContext.Set<Profile>()
.Include(x => x.Prefix)
.Select(x => new
{
profileId = x.Id,
citizenId = x.CitizenId,
prefix = x.Prefix.Name,
firstName = x.FirstName,
lastName = x.LastName,
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
})
.ToListAsync())
.FirstOrDefault(x => x.fullName == command.ChairManFullName);
if (p1 != null)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = p1.citizenId!,
Prefix = p1.prefix!,
FirstName = p1.firstName!,
LastName = p1.lastName!,
RefPlacementProfileId = p1.profileId,
};
seq++;
result.Add(receiver);
}
var p2 = (await _dbContext.Set<Profile>()
.Include(x => x.Prefix)
.Select(x => new
{
profileId = x.Id,
citizenId = x.CitizenId,
prefix = x.Prefix.Name,
firstName = x.FirstName,
lastName = x.LastName,
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
})
.ToListAsync())
.FirstOrDefault(x => x.fullName == command.Member1FullName);
if (p2 != null)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = p2.citizenId!,
Prefix = p2.prefix!,
FirstName = p2.firstName!,
LastName = p2.lastName!,
RefPlacementProfileId = p2.profileId,
};
seq++;
result.Add(receiver);
}
var p3 = (await _dbContext.Set<Profile>()
.Include(x => x.Prefix)
.Select(x => new
{
profileId = x.Id,
citizenId = x.CitizenId,
prefix = x.Prefix.Name,
firstName = x.FirstName,
lastName = x.LastName,
fullName = $"{x.Prefix.Name}{x.FirstName} {x.LastName}"
})
.ToListAsync())
.FirstOrDefault(x => x.fullName == command.Member2FullName);
if (p3 != null)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = p3.citizenId!,
Prefix = p3.prefix!,
FirstName = p3.firstName!,
LastName = p3.lastName!,
RefPlacementProfileId = p3.profileId,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver11Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["Node:API"];
var apiUrl = $"{baseAPI}/report/pass";
var response = new PassProbationResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
var seq = 1;
foreach (var d in response!.data)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver12Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["Node:API"];
var apiUrl = $"{baseAPI}/report/not-pass";
var response = new PassProbationResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassProbationResponse>(result);
var seq = 1;
foreach (var d in response!.data)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver13Async(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-13")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementTransfer>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-14 - คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver14Async(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-14")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementReceive>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-15 - คำสั่งให้ช่วยราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver15Async(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-15")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementOfficer>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-16 - คำสั่งส่งตัวกลับ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver16Async(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-16")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementRepatriation>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver17Async(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-17")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementResign>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-18 - คำสั่งให้ออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver18Async(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-18")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementOut>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-19 - คำสั่งปลดออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver19Async(Command command, string token)
{
try
{
var resultData = 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-19")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementDischarge>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.Profile!.CitizenId!,
Prefix = item.Profile!.Prefix!.Name,
FirstName = item.Profile!.FirstName!,
LastName = item.Profile!.LastName!,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
resultData.Add(receiver);
}
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-19")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver20Async(Command command, string token)
{
try
{
var resultData = 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-20")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementExpulsion>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.Where(x => !otherCommandReceivers.Contains(x.Profile!.CitizenId!))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.Profile!.CitizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.Profile!.CitizenId!,
Prefix = item.Profile!.Prefix!.Name,
FirstName = item.Profile!.FirstName!,
LastName = item.Profile!.LastName!,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
resultData.Add(receiver);
}
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-20")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver21Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile-employee/report";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.id,
RefDisciplineId = d.id,
Organization = d.organization,
PositionName = d.positionName,
PositionLevel = d.positionLevel,
PositionType = d.positionType,
PositionNumber = d.positionNumber,
BirthDate = d.birthDate,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-22 - คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver22Async(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-22")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.Where(x => x.type == "EMPLOYEE")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-23 - คำสั่งให้ลูกจ้างออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver23Async(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-23")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementResign>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
// <summary>
/// C-PM-24
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver24Async(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-24")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<PlacementAppointment>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => x.type == "EMPLOYEE")
.Where(x => x.Status.Trim().ToUpper() == "REPORT")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-25
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver25Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-25")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-26
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver26Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-26")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-27
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver27Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-27")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-28
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver28Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-28")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-29
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver29Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-29")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-30
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver30Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-30")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-31
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver31Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}";
var commandType = await _dbContext.Set<CommandType>()
.Where(x => x.CommandCode.Trim().ToUpper() == "C-PM-31")
.FirstOrDefaultAsync();
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
if (commandType == null || commandType.Id != d.commandId)
continue;
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-32
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver32Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/reject/{command.ComplaintId}";
var response = new PassDisciplineResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassDisciplineResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}";
using (var _client = new HttpClient())
{
_client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Get, _apiUrl);
var _res = await _client.SendAsync(_req);
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
if (org == null || org.result == null)
continue;
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = org.result.citizenId == null ? "" : org.result.citizenId,
Prefix = org.result.prefix == null ? "" : org.result.prefix,
FirstName = org.result.firstName == null ? "" : org.result.firstName,
LastName = org.result.lastName == null ? "" : org.result.lastName,
RefPlacementProfileId = org.result.profileId == null ? null : Guid.Parse(org.result.profileId),
RefDisciplineId = d.id,
Amount = 0,
};
seq++;
resultData.Add(receiver);
}
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-33
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver33Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/33/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-34
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver34Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/34/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-35
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver35Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/35/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-36
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver36Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/36/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-37
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver37Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/37/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-38
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver38Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/38/{command.SalaryPeriodId}";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-40
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver40Async(Command command, string token)
{
try
{
var resultData = new List<CommandReceiver>();
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/pos/act/profile";
var response = new PassSalaryResponse();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
var res = await client.SendAsync(req);
var result = await res.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject<PassSalaryResponse>(result);
var seq = 1;
foreach (var d in response!.result)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = d.citizenId,
Prefix = d.prefix == null ? "" : d.prefix,
FirstName = d.firstName,
LastName = d.lastName,
RefPlacementProfileId = d.profileId == null ? null : Guid.Parse(d.profileId),
RefDisciplineId = d.id,
};
seq++;
resultData.Add(receiver);
}
}
return resultData;
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-41
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task<List<CommandReceiver>> GetReceiver41Async(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-41")
.Where(x => x.Command.Id != command.Id)
.Select(x => x.CitizenId)
.ToListAsync();
// 2. Query
var appointPeople = await _dbContext.Set<RetirementResign>()
.Where(x => !otherCommandReceivers.Contains(x.citizenId))
.Where(x => (x.Status.Trim().ToUpper() == "DONE" && x.ActiveDate > DateTime.Now.AddDays(1)) || x.Status.Trim().ToUpper() == "DONECANCEL")
.OrderBy(x => x.citizenId)
.ToListAsync();
// 3. Create new Record
var seq = 1;
foreach (var item in appointPeople)
{
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.citizenId == null ? "" : item.citizenId,
Prefix = item.prefix == null ? "" : item.prefix,
FirstName = item.firstName == null ? "" : item.firstName,
LastName = item.lastName == null ? "" : item.lastName,
RefPlacementProfileId = item.Id,
Amount = item.AmountOld,
};
seq++;
result.Add(receiver);
}
return result;
}
catch
{
throw;
}
}
#endregion
#region " Execute and Deploy "
private async Task ExecuteCommandByTypeAsync(Command command, string token = "")
{
switch (command.CommandType.CommandCode.Trim().ToUpper())
{
case "C-PM-01":
case "C-PM-02":
await ExecuteCommand01_02Async(command, token);
break;
case "C-PM-03":
await ExecuteCommand03Async(command, token);
break;
case "C-PM-04":
await ExecuteCommand04Async(command, token);
break;
case "C-PM-39":
await ExecuteCommand39Async(command, token);
break;
case "C-PM-05":
await ExecuteCommand05Async(command, token);
break;
case "C-PM-06":
await ExecuteCommand06Async(command, token);
break;
case "C-PM-07":
await ExecuteCommand07Async(command, token);
break;
case "C-PM-08":
await ExecuteCommand08Async(command, token);
break;
case "C-PM-09":
await ExecuteCommand09Async(command, token);
break;
case "C-PM-10":
await ExecuteCommand10Async(command);
break;
case "C-PM-11":
await ExecuteCommand11Async(command, token);
break;
case "C-PM-12":
await ExecuteCommand12Async(command, token);
break;
case "C-PM-13":
await ExecuteCommand13Async(command, token);
break;
case "C-PM-14":
await ExecuteCommand14Async(command, token);
break;
case "C-PM-15":
await ExecuteCommand15Async(command, token);
break;
case "C-PM-16":
await ExecuteCommand16Async(command, token);
break;
case "C-PM-17":
await ExecuteCommand17Async(command, token);
break;
case "C-PM-18":
await ExecuteCommand18Async(command, token);
break;
case "C-PM-19":
await ExecuteCommand19Async(command, token);
break;
case "C-PM-20":
await ExecuteCommand20Async(command, token);
break;
case "C-PM-21":
await ExecuteCommand21Async(command, token);
break;
case "C-PM-22":
await ExecuteCommand22Async(command, token);
break;
case "C-PM-23":
await ExecuteCommand23Async(command, token);
break;
case "C-PM-24":
await ExecuteCommand24Async(command, token);
break;
case "C-PM-25":
await ExecuteCommand25Async(command, token);
break;
case "C-PM-26":
await ExecuteCommand26Async(command, token);
break;
case "C-PM-27":
await ExecuteCommand27Async(command, token);
break;
case "C-PM-28":
await ExecuteCommand28Async(command, token);
break;
case "C-PM-29":
await ExecuteCommand29Async(command, token);
break;
case "C-PM-30":
await ExecuteCommand30Async(command, token);
break;
case "C-PM-31":
await ExecuteCommand31Async(command, token);
break;
case "C-PM-32":
await ExecuteCommand32Async(command, token);
break;
case "C-PM-33":
await ExecuteCommand33Async(command, token);
break;
case "C-PM-34":
await ExecuteCommand34Async(command, token);
break;
case "C-PM-35":
await ExecuteCommand35Async(command, token);
break;
case "C-PM-36":
await ExecuteCommand36Async(command, token);
break;
case "C-PM-37":
await ExecuteCommand37Async(command, token);
break;
case "C-PM-38":
await ExecuteCommand38Async(command, token);
break;
case "C-PM-40":
await ExecuteCommand40Async(command, token);
break;
case "C-PM-41":
await ExecuteCommand41Async(command, token);
break;
default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement);
}
}
/// <summary>
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้,
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand01_02Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
// create new profile
foreach (var recv in command.Receivers)
{
// query placement Profile
var placementProfile = await _dbContext.Set<PlacementProfile>()
.Include(x => x.PlacementProfileDocs)
.ThenInclude(x => x.Document)
.Include(x => x.PositionPath)
.Include(x => x.PositionPathSide)
.Include(x => x.PositionType)
.Include(x => x.PositionLine)
.Include(x => x.PositionLevel)
.Include(x => x.PositionNumber)
.Include(x => x.PlacementCertificates)
.Include(x => x.PlacementEducations)
.ThenInclude(x => x.EducationLevel)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.ThenInclude(x => x.OrganizationShortName)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.PositionMaster)
.ThenInclude(x => x.PositionExecutive)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.PositionMaster)
.ThenInclude(x => x.PositionExecutiveSide)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.PositionMaster)
.ThenInclude(x => x.PositionLine)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x.Organization)
.ThenInclude(x => x.OrganizationOrganization)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception("Invalid placement profile: " + recv.RefPlacementProfileId);
/*ข้อมูล Profile ใหม่*/
var apiUrl = $"{_configuration["API"]}/org/profile/all";
var profileId = string.Empty;
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
rank = string.Empty,
prefix = placementProfile.Prefix == null ? string.Empty : placementProfile.Prefix,
firstName = placementProfile.Firstname == null ? string.Empty : placementProfile.Firstname,
lastName = placementProfile.Lastname == null ? string.Empty : placementProfile.Lastname,
citizenId = placementProfile.CitizenId == null ? string.Empty : placementProfile.CitizenId,
position = placementProfile.positionName == null ? string.Empty : placementProfile.positionName,
posLevelId = placementProfile.posLevelId == null ? string.Empty : placementProfile.posLevelId,
posTypeId = placementProfile.posTypeId == null ? string.Empty : placementProfile.posTypeId,
email = placementProfile.Email == null ? string.Empty : placementProfile.Email,
phone = placementProfile.MobilePhone == null ? string.Empty : placementProfile.MobilePhone,
keycloak = string.Empty,
isProbation = true,
isLeave = false,
dateRetire = (DateTime?)null,
dateAppoint = command.CommandAffectDate == null ? null : command.CommandAffectDate,
dateStart = command.CommandAffectDate == null ? null : command.CommandAffectDate,
govAgeAbsent = 0,
govAgePlus = 0,
birthDate = placementProfile.DateOfBirth == null ? (DateTime?)null : placementProfile.DateOfBirth,
reasonSameDate = (DateTime?)null,
ethnicity = placementProfile.Race == null ? string.Empty : placementProfile.Race,
telephoneNumber = placementProfile.Telephone == null ? string.Empty : placementProfile.Telephone,
nationality = placementProfile.Nationality == null ? string.Empty : placementProfile.Nationality,
gender = placementProfile.Gender == null ? string.Empty : placementProfile.Gender,
relationship = placementProfile.Relationship == null ? string.Empty : placementProfile.Relationship,
religion = placementProfile.Religion == null ? string.Empty : placementProfile.Religion,
bloodGroup = string.Empty,
registrationAddress = placementProfile.RegistAddress == null ? string.Empty : placementProfile.RegistAddress,
registrationProvinceId = (String?)null,
registrationDistrictId = (String?)null,
registrationSubDistrictId = (String?)null,
registrationZipCode = placementProfile.RegistZipCode == null ? string.Empty : placementProfile.RegistZipCode,
currentAddress = placementProfile.CurrentAddress == null ? string.Empty : placementProfile.CurrentAddress,
currentProvinceId = (String?)null,
currentDistrictId = (String?)null,
currentSubDistrictId = (String?)null,
currentZipCode = placementProfile.CurrentZipCode == null ? string.Empty : placementProfile.CurrentZipCode,
});
var _result = await _res.Content.ReadAsStringAsync();
profileId = JsonConvert.DeserializeObject<PlacementProfileId>(_result).result;
}
if (placementProfile.PlacementEducations != null)
{
var apiUrlEdu = $"{_configuration["API"]}/org/profile/educations";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
foreach (var edu in placementProfile.PlacementEducations)
{
var _res = await client.PostAsJsonAsync(apiUrlEdu, new
{
profileId = profileId,
country = edu.Country == null ? string.Empty : edu.Country,
degree = edu.Degree == null ? string.Empty : edu.Degree,
duration = edu.Duration == null ? string.Empty : edu.Duration,
durationYear = edu.DurationYear == null ? 0 : edu.DurationYear,
field = edu.Field == null ? string.Empty : edu.Field,
finishDate = edu.FinishDate == null ? (DateTime?)null : edu.FinishDate,
fundName = edu.FundName == null ? string.Empty : edu.FundName,
gpa = edu.Gpa == null ? string.Empty : edu.Gpa,
institute = edu.Institute == null ? string.Empty : edu.Institute,
other = edu.Other == null ? string.Empty : edu.Other,
startDate = edu.StartDate == null ? (DateTime?)null : edu.StartDate,
endDate = edu.EndDate == null ? (DateTime?)null : edu.EndDate,
educationLevel = edu.EducationLevel == null ? string.Empty : edu.EducationLevel.Name,
educationLevelId = string.Empty,
positionPath = edu.PositionPath == null ? null : edu.PositionPath,
positionPathId = string.Empty,
isDate = edu.IsDate,
isEducation = edu.IsEducation,
note = string.Empty,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
}
if (placementProfile.PlacementCertificates != null)
{
var apiUrlCer = $"{_configuration["API"]}/org/profile/certificate";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
foreach (var cer in placementProfile.PlacementCertificates)
{
var _res = await client.PostAsJsonAsync(apiUrlCer, new
{
profileId = profileId,
expireDate = cer.ExpireDate == null ? (DateTime?)null : cer.ExpireDate,
issueDate = cer.IssueDate == null ? (DateTime?)null : cer.IssueDate,
certificateNo = cer.CertificateNo == null ? string.Empty : cer.CertificateNo,
certificateType = cer.CertificateType == null ? string.Empty : cer.CertificateType,
issuer = cer.Issuer == null ? string.Empty : cer.Issuer,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
}
var apiUrlSalary = $"{_configuration["API"]}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = profileId,
date = command.CommandAffectDate == null ? (DateTime?)null : command.CommandAffectDate,
amount = placementProfile.Amount,
positionSalaryAmount = placementProfile.PositionSalaryAmount,
mouthSalaryAmount = placementProfile.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.positionName == null ? string.Empty : placementProfile.positionName,
positionLine = string.Empty,
positionPathSide = string.Empty,
positionExecutive = string.Empty,
positionType = placementProfile.posTypeName == null ? string.Empty : placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName == null ? string.Empty : placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.PlacementStatus = "CONTAIN";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand03Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.positionName,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.PlacementStatus = "CONTAIN";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-04 - คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand04Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.positionName,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.PlacementStatus = "CONTAIN";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-39 - คำสั่งเลื่อน : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand39Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.positionName,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งเลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.PlacementStatus = "CONTAIN";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-05 - คำสั่งแต่งตั้ง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand05Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementAppointment>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.position,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งแต่งตั้ง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (recv.RefPlacementProfileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-06 - คำสั่งเลื่อน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand06Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementAppointment>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.position,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งเลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งเลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-07 - คำสั่งย้าย
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand07Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<PlacementAppointment>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.position,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งย้าย คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand08Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<RetirementOther>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.PositionNumberOld,
position = placementProfile.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.PositionTypeOld,
positionLevel = placementProfile.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPILeave = _configuration["API"];
var apiUrlLeave = $"{baseAPI}/org/profile/leave/{placementProfile.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlLeave);
string? _null = null;
var _res = await client.PostAsJsonAsync(apiUrlLeave, new
{
isLeave = false,
leaveReason = _null,
dateLeave = _null,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand09Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var placementProfile = await _dbContext.Set<RetirementOther>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.PositionNumberOld,
position = placementProfile.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.PositionTypeOld,
positionLevel = placementProfile.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPILeave = _configuration["API"];
var apiUrlLeave = $"{baseAPI}/org/profile/leave/{placementProfile.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlLeave);
string? _null = null;
var _res = await client.PostAsJsonAsync(apiUrlLeave, new
{
isLeave = false,
leaveReason = _null,
dateLeave = _null,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
// <summary>
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand10Async(Command command)
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<Profile>()
.Include(x => x.Salaries)
.ThenInclude(x => x.PositionLevel)
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault();
var order = 1;
if (lastSarary != null && lastSarary.Order != null)
order = lastSarary.Order.Value + 1;
var salary = new ProfileSalary
{
Order = order,
Date = command.CommandAffectDate,
Amount = lastSarary == null ? null : lastSarary.Amount,
PositionSalaryAmount = lastSarary == null ? null : lastSarary.PositionSalaryAmount,
MouthSalaryAmount = lastSarary == null ? null : lastSarary.MouthSalaryAmount,
SalaryClass = "",
SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
OcId = lastSarary == null ? null : lastSarary.OcId,
PositionId = lastSarary == null ? null : lastSarary.PositionId,
PositionLevel = lastSarary == null ? null : lastSarary.PositionLevel,
PositionLineId = lastSarary == null ? null : lastSarary.PositionLineId,
PositionTypeId = lastSarary == null ? null : lastSarary.PositionTypeId,
OrganizationShortNameId = lastSarary == null ? null : lastSarary.OrganizationShortNameId,
PosNoId = lastSarary == null ? null : lastSarary.PosNoId,
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
CommandTypeName = command.CommandType.Name,
PositionEmployeeGroupId = null,
PositionEmployeeLevelId = null,
PositionEmployeePositionId = null,
PositionEmployeePositionSideId = null,
PosNoEmployee = "",
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
PositionExecutiveId = lastSarary == null ? null : lastSarary.PositionExecutiveId,
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
IsActive = true,
CreatedAt = DateTime.Now,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
};
if (lastSarary != null && lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId;
if (lastSarary != null && lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId;
data.Salaries.Add(salary);
// update placementstatus
//data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Id,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = data.Id,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand11Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/command11/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}"
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = placementProfile.posmasterId,
// positionId = placementProfile.positionId,
// profileId = placementProfile.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand12Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/command12/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = placementProfile.posmasterId,
// positionId = placementProfile.positionId,
// profileId = placementProfile.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand13Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementTransfer>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
// var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
// var _res = await client.PostAsJsonAsync(apiUrl, new
// {
// isLeave = true,
// leaveReason = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ",
// dateLeave = command.CommandAffectDate,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = data.posmasterId,
// positionId = data.positionId,
// profileId = data.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// // update placementstatus
data.Status = "DONE";
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-14 - คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand14Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
// create new profile
foreach (var recv in command.Receivers)
{
// query placement Profile
var placementProfile = await _dbContext.Set<PlacementReceive>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception("Invalid placement profile: " + recv.RefPlacementProfileId);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = placementProfile.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = placementProfile.posMasterNo == null ? "" :
placementProfile.node == 4 ? $"{placementProfile.child4ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 3 ? $"{placementProfile.child3ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 2 ? $"{placementProfile.child2ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 1 ? $"{placementProfile.child1ShortName}{placementProfile.posMasterNo}" :
placementProfile.node == 0 ? $"{placementProfile.rootShortName}{placementProfile.posMasterNo}" : "",
position = placementProfile.position,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = placementProfile.posTypeName,
positionLevel = placementProfile.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "รับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = placementProfile.posmasterId,
positionId = placementProfile.positionId,
profileId = placementProfile.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
placementProfile.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (placementProfile.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับโอนเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(placementProfile.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-15 - คำสั่งให้ช่วยราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand15Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementOfficer>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งให้ช่วยราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = data.posmasterId,
// positionId = data.positionId,
// profileId = data.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// // update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-16 - คำสั่งส่งตัวกลับ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand16Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementRepatriation>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งส่งตัวกลับ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = data.posmasterId,
// positionId = data.positionId,
// profileId = data.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คำสั่งส่งตัวกลับ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand17Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<RetirementResign>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
isLeave = true,
leaveReason = "ลาออกจากราชการ",
dateLeave = command.CommandAffectDate,
});
var _result = await _res.Content.ReadAsStringAsync();
}
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = data.posmasterId,
// positionId = data.positionId,
// profileId = data.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// // update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-18 - คำสั่งให้ออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand18Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<RetirementOut>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
isLeave = true,
leaveReason = "ให้ออกจากราชการ",
dateLeave = command.CommandAffectDate,
});
var _result = await _res.Content.ReadAsStringAsync();
}
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งให้ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = data.posmasterId,
// positionId = data.positionId,
// profileId = data.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-19 - คำสั่งปลดออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand19Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/command19/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = placementProfile.posmasterId,
// positionId = placementProfile.positionId,
// profileId = placementProfile.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
var dataSend = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ ปลดออกจากราชการ"
});
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, _apiUrl);
var res = await client.PostAsJsonAsync(_apiUrl, new { result = dataSend });
var result = await res.Content.ReadAsStringAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งปลดออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand20Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/command20/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
// var _res = await client.PostAsJsonAsync(apiUrlOrg, new
// {
// posmasterId = placementProfile.posmasterId,
// positionId = placementProfile.positionId,
// profileId = placementProfile.profileId,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
var dataSend = command.Receivers.Select(x => new
{
personId = x.RefPlacementProfileId,
id = x.RefDisciplineId,
commandAffectDate = command.CommandAffectDate,
commandNo = command.CommandNo,
commandYear = command.CommandYear.ToInteger().ToThaiYear(),
detail = "คำสั่งลงโทษ ไล่ออกจากราชการ"
});
var _baseAPI = _configuration["API"];
var _apiUrl = $"{_baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, _apiUrl);
var res = await client.PostAsJsonAsync(_apiUrl, new { result = dataSend });
var result = await res.Content.ReadAsStringAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งไล่ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>GenerateCommandReportType25_Cover
private async Task ExecuteCommand21Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
personId = x.RefPlacementProfileId.ToString(),
id = x.RefDisciplineId.ToString(),
templateDoc = "คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
amount = x.Amount,
positionSalaryAmount = x.PositionSalaryAmount,
mouthSalaryAmount = x.MouthSalaryAmount,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile-employee/report/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-22 - คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน)
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand22Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementAppointment>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile-employee/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileEmployeeId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.posMasterNo == null ? "" :
data.node == 4 ? $"{data.child4ShortName}{data.posMasterNo}" :
data.node == 3 ? $"{data.child3ShortName}{data.posMasterNo}" :
data.node == 2 ? $"{data.child2ShortName}{data.posMasterNo}" :
data.node == 1 ? $"{data.child1ShortName}{data.posMasterNo}" :
data.node == 0 ? $"{data.rootShortName}{data.posMasterNo}" : "",
position = data.position,
positionType = data.posTypeName,
positionLevel = data.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/employee/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = data.posmasterId,
positionId = data.positionId,
profileId = data.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
// รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-23 - คำสั่งให้ลูกจ้างออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand23Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<RetirementResign>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile-employee/salary/{data.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Put, apiUrl);
var _res = await client.PutAsJsonAsync(apiUrl, new
{
isLeave = true,
leaveReason = "ลาออกจากราชการ",
dateLeave = command.CommandAffectDate,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// // update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งให้ลูกจ้างออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// // send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-24 - คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย)
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand24Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<PlacementAppointment>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrlSalary = $"{baseAPI}/org/profile-employee/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileEmployeeId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.posMasterNo == null ? "" :
data.node == 4 ? $"{data.child4ShortName}{data.posMasterNo}" :
data.node == 3 ? $"{data.child3ShortName}{data.posMasterNo}" :
data.node == 2 ? $"{data.child2ShortName}{data.posMasterNo}" :
data.node == 1 ? $"{data.child1ShortName}{data.posMasterNo}" :
data.node == 0 ? $"{data.rootShortName}{data.posMasterNo}" : "",
position = data.position,
positionType = data.posTypeName,
positionLevel = data.posLevelName,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/employee/pos/report/current";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlOrg);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
posmasterId = data.posmasterId,
positionId = data.positionId,
profileId = data.profileId,
});
var _result = await _res.Content.ReadAsStringAsync();
}
// update placementstatus
data.Status = "DONE";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
// รอเอาข้อมูลที่ได้มาส่ง inbox noti ให้ผู้รับคำสั่ง
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งจ้างและแต่งตั้งลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-25 - คำสั่งพักจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand25Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ พักจากราชการ"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command25/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งพักจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งพักจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งพักจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-26 - คำสั่งให้ออกจากราชการไว้ก่อน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand26Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ ให้ออกจากราชการไว้ก่อน"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command26/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งให้ออกจากราชการไว้ก่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งให้ออกจากราชการไว้ก่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ออกจากราชการไว้ก่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-27 - คำสั่งลงโทษ ภาคทัณฑ์
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand27Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ ลงโทษ ภาคทัณฑ์"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command27/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งลงโทษ ภาคทัณฑ์ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งลงโทษ ภาคทัณฑ์ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งลงโทษ ภาคทัณฑ์ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-28 - คำสั่งลงโทษ ตัดเงินเดือน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand28Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command28/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งลงโทษ ตัดเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งลงโทษ ตัดเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งลงโทษ ตัดเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-29 - คำสั่งลงโทษ ลดขั้นเงินเดือน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand29Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งลงโทษ ลดขั้นเงินเดือน"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command29/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งลงโทษ ลดขั้นเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งลงโทษ ลดขั้นเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-30 - คำสั่งเพิ่มโทษ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand30Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งเพิ่มโทษ"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command30/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งเพิ่มโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งเพิ่มโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเพิ่มโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-31 - คำสั่งงดโทษ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand31Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งงดโทษ"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command31/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งงดโทษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งงดโทษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งงดโทษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-32 - คำสั่งยุติเรื่อง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand32Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
CommandAffectDate = command.CommandAffectDate,
CommandNo = command.CommandNo,
CommandYear = command.CommandYear.ToInteger().ToThaiYear(),
Detail = "คำสั่งยุติเรื่อง"
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/discipline/result/report/reject/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var apiUrl2 = $"{baseAPI}/org/profile/command32/{recv.RefPlacementProfileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl2);
var _res = await client.PostAsJsonAsync(apiUrl2, new
{
profileId = recv.RefPlacementProfileId,
date = command.CommandAffectDate,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
salaryRef = "คำสั่งยุติเรื่อง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-33 - คำสั่งเลื่อนเงินเดือน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand33Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งเลื่อนเงินเดือน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/33/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งเลื่อนเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งเลื่อนเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งเลื่อนเงินเดือน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อนเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อนเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อนเงินเดือน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-34 - คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand34Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/34/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-35 - คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand35Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/35/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-36 - คำสั่งเลื่อนขั้นค่าจ้าง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand36Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งเลื่อนขั้นค่าจ้าง คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/36/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งเลื่อนขั้นค่าจ้าง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งเลื่อนขั้นค่าจ้าง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งเลื่อนขั้นค่าจ้าง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งเลื่อนขั้นค่าจ้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งเลื่อนขั้นค่าจ้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งเลื่อนขั้นค่าจ้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-37 - คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand37Async(Command command, string token = "")
{
try
{
var data = command.Receivers.Select(x => new
{
PersonId = x.RefPlacementProfileId,
Id = x.RefDisciplineId,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/salary/report/command/37/resume";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
var result = await res.Content.ReadAsStringAsync();
}
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = recv.RefPlacementProfileId.Value,
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-38 - คำสั่งปรับโครงสร้าง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand38Async(Command command, string token = "")
{
try
{
// var data = command.Receivers.Select(x => new
// {
// PersonId = x.RefPlacementProfileId,
// Id = x.RefDisciplineId,
// });
// var baseAPI = _configuration["API"];
// var apiUrl = $"{baseAPI}/salary/report/command/38/resume";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
// var req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
// var res = await client.PostAsJsonAsync(apiUrl, new { result = data });
// var result = await res.Content.ReadAsStringAsync();
// }
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
// foreach (var recv in command.Receivers)
// {
// // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// // Send noti inbox and email
// var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
// var body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
// _emailSenderService.SendMail(subject, body, "dev@frappet.com");
// var inbox = new Inbox
// {
// Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
// ReceiverUserId = recv.RefPlacementProfileId.Value,
// Payload = payload_str,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// };
// _dbContext.Set<Inbox>().Add(inbox);
// var noti = new Notification
// {
// Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
// ReceiverUserId = recv.RefPlacementProfileId.Value,
// Type = "LINK",
// Payload = payload_str,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// };
// _dbContext.Set<Notification>().Add(noti);
// await _dbContext.SaveChangesAsync();
// }
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งปรับโครงสร้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งปรับโครงสร้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งปรับโครงสร้าง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-40 - คำสั่งให้ข้าราชการรักษาการในตำแหน่ง
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand40Async(Command command, string token = "")
{
try
{
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งให้ข้าราชการรักษาการในตำแหน่ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งให้ข้าราชการรักษาการในตำแหน่ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งให้ข้าราชการรักษาการในตำแหน่ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
/// <summary>
/// C-PM-41 - คำสั่งยกเลิกการลาออก
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
private async Task ExecuteCommand41Async(Command command, string token = "")
{
try
{
// create command payload
var payload_attach = command.Documents
.Select(x => new PayloadAttachment
{
name = x.Category == "cover" ? "สำเนาคำสั่ง" : "สำเนาเอกสารแนบท้าย",
url = $"{_configuration["API"]}/order/download/attachment/{x.Document.Id}"
})
.ToList();
var payload = new CommandPayload()
{
attachments = payload_attach
};
var payload_str = JsonConvert.SerializeObject(payload);
foreach (var recv in command.Receivers)
{
var data = await _dbContext.Set<RetirementResign>()
.FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId);
if (data == null)
throw new Exception(GlobalMessages.DataNotFound);
var baseAPI = _configuration["API"];
var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
string? _null = null;
var _res = await client.PostAsJsonAsync(apiUrl, new
{
isLeave = false,
leaveReason = _null,
dateLeave = _null,
});
var _result = await _res.Content.ReadAsStringAsync();
}
var apiUrlSalary = $"{baseAPI}/org/profile/salary";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrlSalary);
var _res = await client.PostAsJsonAsync(apiUrlSalary, new
{
profileId = data.profileId,
date = command.CommandAffectDate,
amount = recv.Amount,
positionSalaryAmount = recv.PositionSalaryAmount,
mouthSalaryAmount = recv.MouthSalaryAmount,
posNo = data.PositionNumberOld,
position = data.PositionOld,
positionLine = "",
positionPathSide = "",
positionExecutive = "",
positionType = data.PositionTypeOld,
positionLevel = data.PositionLevelOld,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}",
templateDoc = "คำสั่งยกเลิกการลาออก คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}",
});
var _result = await _res.Content.ReadAsStringAsync();
}
// // update placementstatus
data.Status = "DONEREJECT";
await _dbContext.SaveChangesAsync();
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คุณได้รับคำสั่งยกเลิกการลาออก เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
if (data.profileId != null)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คุณได้รับคำสั่งยกเลิกการลาออก เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยกเลิกการลาออก เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(data.profileId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
await _dbContext.SaveChangesAsync();
}
// send cc noti inbox
foreach (var cc in command.Deployments)
{
if (cc.IsSendInbox)
{
var inbox = new Inbox
{
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
Body = $"คำสั่งยกเลิกการลาออก คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Inbox>().Add(inbox);
}
if (cc.IsSendMail)
{
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
var subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
var body = $"คำสั่งยกเลิกการลาออก คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}";
_emailSenderService.SendMail(subject, body, "dev@frappet.com");
}
var noti = new Notification
{
Body = $"คำสั่งยกเลิกการลาออก คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}",
ReceiverUserId = Guid.Parse(cc.ReceiveUserId),
Type = "LINK",
Payload = payload_str,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
_dbContext.Set<Notification>().Add(noti);
}
// change command status
var cmdStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(x => x.Sequence == 5);
command.CommandStatusId = cmdStatus!.Id;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
#endregion
#region " Regenerate Json File "
#endregion
#endregion
#region " Override "
public override async Task<Command?> GetByIdAsync(Guid id)
{
return await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.CommandType)
.Include(x => x.Documents)
.ThenInclude(x => x.Document) //--REmove
.Include(x => x.Receivers)
.Include(x => x.CommandStatus)
.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task<Command?> GetByIdWithPlacementAsync(Guid id)
{
return await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.CommandType)
.Include(x => x.Documents)
.ThenInclude(x => x.Document)
.Include(x => x.Receivers)
.Include(x => x.CommandStatus)
.FirstOrDefaultAsync(x => x.Id == id);
}
public override async Task<IReadOnlyList<Command>> GetAllAsync()
{
return await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.CommandType)
.Include(x => x.CommandStatus)
.Include(x => x.Receivers)
.OrderBy(x => x.CommandType.CommandCode)
.ThenByDescending(x => x.CommandAffectDate)
.ToListAsync();
}
public override async Task<Command> AddAsync(Command command)
{
var status = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == 1);
command.CommandStatus = status!;
_dbContext.Attatch(status!);
return await base.AddAsync(command);
}
public override async Task<Command> UpdateAsync(Command entity)
{
// attatch
_dbContext.Attatch(entity.CommandStatus);
_dbContext.Attatch(entity.CommandType);
if (entity.Placement != null)
_dbContext.Attatch(entity.Placement);
return await base.UpdateAsync(entity);
}
#endregion
#region " Execute Command "
public async Task ExecuteCommandAsync(Guid id, string token = "")
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.Include(x => x.Deployments)
.Include(x => x.CommandType)
.Include(x => x.Documents)
.ThenInclude(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
await ExecuteCommandByTypeAsync(command, token);
}
catch
{
throw;
}
}
#endregion
#region " Command Receiver "
public async Task SaveSelectedReceiverAsync(Guid id, List<Guid> selected, string token = "")
{
try
{
Command command = null;
var c = await _dbContext.Set<Command>()
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
if (c == null)
throw new Exception(GlobalMessages.CommandNotFound);
switch (c.CommandType.CommandCode.ToUpper())
{
case "C-PM-01":
case "C-PM-02":
case "C-PM-03":
case "C-PM-04":
command = await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
break;
case "C-PM-39":
command = await _dbContext.Set<Command>()
.Include(x => x.Placement)
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
break;
default:
command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
break;
}
var ap = (await GetReceiverForByCommndTypeAsync(command, token)).Where(x => selected.Contains(x.RefPlacementProfileId!.Value));
//var appointPeople = await _dbContext.Set<PlacementProfile>()
// .Include(x => x.Prefix)
// .Include(x => x.OrganizationPosition)
// .ThenInclude(x => x!.Organization)
// //.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
// .Where(x => selected.Contains(x.Id))
// .OrderBy(x => x.ExamNumber)
// .ToListAsync();
_dbContext.Set<CommandReceiver>().RemoveRange(command.Receivers);
await _dbContext.SaveChangesAsync();
var seq = 1;
foreach (var item in ap)
{
PlacementSalaryResponse salary = new();
// ให้ Update Salary เฉพาะของ Command 01-04
switch (command.CommandType.CommandCode.ToUpper())
{
case "C-PM-01":
case "C-PM-02":
case "C-PM-03":
case "C-PM-04":
salary = await GetPlacementSalaryAsync(item.RefPlacementProfileId.Value);
break;
case "C-PM-39":
salary = await GetPlacementSalaryAsync(item.RefPlacementProfileId.Value);
break;
default:
salary = await GetCommandReceiverSalary(item.RefPlacementProfileId.Value, item.Amount, item.MouthSalaryAmount, item.PositionSalaryAmount);
break;
}
var receiver = new CommandReceiver
{
Sequence = seq,
CitizenId = item.CitizenId!,
Prefix = item.Prefix,
FirstName = item.FirstName!,
LastName = item.LastName!,
RefPlacementProfileId = item.RefPlacementProfileId,
RefDisciplineId = item.RefDisciplineId,
Amount = salary == null ? 0 : salary.SalaryAmount,
MouthSalaryAmount = salary == null ? 0 : salary.MonthSalaryAmount,
PositionSalaryAmount = salary == null ? 0 : salary.PositionSalaryAmount,
Organization = item.Organization,
PositionName = item.PositionName,
PositionLevel = item.PositionLevel,
PositionType = item.PositionType,
PositionNumber = item.PositionNumber,
BirthDate = item.BirthDate,
};
seq++;
command.Receivers.Add(receiver);
}
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<List<CommandReceiver>> GetReceiverForCommandAsync(Guid id, string token = "")
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
return await GetReceiverForByCommndTypeAsync(command, token);
}
catch
{
throw;
}
}
public async Task<List<CommandReceiver>> GetReceiverByCommmandIdAsync(Guid Id)
{
try
{
// ปรับใหม่ให้อ่านจาก database ล้วนๆ
var command = await _dbContext.Set<Command>()
.Include(x => x.Receivers)
.Include(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == Id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
if (command.Receivers != null && command!.Receivers!.Count > 0)
{
return command.Receivers;
}
else
{
// returrn empty list
return new List<CommandReceiver>();
}
}
}
catch
{
throw;
}
}
public async Task<CommandReceiver> DeleteCommandReceiverAsync(Guid personalId)
{
try
{
var deleted = await _dbContext.Set<CommandReceiver>()
.FirstOrDefaultAsync(x => x.Id == personalId);
if (deleted == null)
throw new Exception(GlobalMessages.DataNotFound);
_dbContext.Set<CommandReceiver>().Remove(deleted);
await _dbContext.SaveChangesAsync();
return deleted;
}
catch
{
throw;
}
}
public async Task<CommandReceiver?> GetCommandReceiverAsync(Guid personalId)
{
try
{
var receiver = await _dbContext.Set<CommandReceiver>()
.Include(x => x.Command)
.ThenInclude(x => x.CommandType)
.FirstOrDefaultAsync(x => x.Id == personalId);
if (receiver == null)
throw new Exception(GlobalMessages.DataNotFound);
return receiver;
}
catch
{
throw;
}
}
public async Task SwapReceiverOrderAsync(Guid personalId, string direction)
{
try
{
var current = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.FirstOrDefaultAsync(x => x.Id == personalId);
if (current == null)
throw new Exception(GlobalMessages.DataNotFound);
var currentSeq = current.Sequence;
var commandID = current.Command!.Id;
switch (direction.Trim().ToLower())
{
case "up":
{
// get prev record
var prev = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(x => x.Command.Id == commandID)
.Where(x => x.Sequence < currentSeq)
.OrderByDescending(x => x.Sequence)
.Take(1)
.FirstOrDefaultAsync();
if (prev != null)
{
var prevSeq = prev.Sequence;
current.Sequence = prevSeq;
prev.Sequence = currentSeq;
await _dbContext.SaveChangesAsync();
}
break;
}
case "down":
{
// get next record
var next = await _dbContext.Set<CommandReceiver>()
.Include(c => c.Command)
.Where(x => x.Command.Id == commandID)
.Where(x => x.Sequence > currentSeq)
.OrderBy(x => x.Sequence)
.Take(1)
.FirstOrDefaultAsync();
if (next != null)
{
var nextSeq = next.Sequence;
current.Sequence = nextSeq;
next.Sequence = currentSeq;
await _dbContext.SaveChangesAsync();
}
break;
}
default: throw new Exception("Invalid swap direction!");
}
}
catch
{
throw;
}
}
#endregion
public async Task<string> GetReceiverPositionByCommandIdAsync(Guid id)
{
try
{
var ret = string.Empty;
var data = await (from r in _dbContext.Set<CommandReceiver>()
.Include(x => x.Command)
join pf in _dbContext.Set<PlacementProfile>()
.Include(x => x.PositionPath)
on r.RefPlacementProfileId equals pf.Id
where r.Command.Id == id
select new
{
r.RefPlacementProfileId,
Position = pf.PositionPath!.Name
}).ToListAsync();
if (data.Count > 0)
{
foreach (var d in data)
{
if (!ret.Contains($"{d.Position},"))
ret += $"{d.Position},";
}
ret = ret.Substring(0, ret.Length - 1);
}
return ret;
}
catch
{
throw;
}
}
public async Task<string> GetReceiverPosition2ByCommandIdAsync(Guid id)
{
try
{
var ret = string.Empty;
var data = await (from r in _dbContext.Set<CommandReceiver>()
.Include(x => x.Command)
join pf in _dbContext.Set<PlacementAppointment>()
//.Include(x => x.PositionPath)
on r.RefPlacementProfileId equals pf.Id
where r.Command.Id == id
select new
{
r.RefPlacementProfileId,
Position = pf.position
}).ToListAsync();
if (data.Count > 0)
{
foreach (var d in data)
{
if (!ret.Contains($"{d.Position},"))
ret += $"{d.Position},";
}
ret = ret.Substring(0, ret.Length - 1);
}
return ret;
}
catch
{
throw;
}
}
public async Task<List<CommandDeployment>> GetDeploymentByCommandIdAsync(Guid id)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Deployments)
.FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
if (command.Deployments != null || command!.Deployments!.Count > 0)
{
return command.Deployments;
}
else
{
var orgPos = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x!.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.ThenInclude(x => x!.OrganizationOrganization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Where(x => x.OrganizationPosition!.IsDirector! == true)
.Where(x => x.OrganizationPosition!.Organization!.Id == command.OwnerGovId)
.FirstOrDefaultAsync();
if (orgPos != null)
{
if (orgPos.Profile != null)
{
var dp = new CommandDeployment
{
Sequence = 1,
ReceiveUserId = orgPos!.Profile!.Id!.ToString("D"),
CitizenId = orgPos!.Profile!.CitizenId!,
Prefix = orgPos!.Profile!.Prefix!.Name,
FirstName = orgPos!.Profile!.FirstName!,
LastName = orgPos!.Profile!.LastName!,
IsSendInbox = true,
IsSendMail = true,
IsSendNotification = true,
OrganizationName = orgPos!.OrganizationPosition!.Organization!.OrganizationOrganization!.Name,
PositionName = orgPos!.OrganizationPosition!.PositionMaster!.PositionPath!.Name
};
command.Deployments.Add(dp);
}
await _dbContext.SaveChangesAsync();
}
// query for new list
return command.Deployments;
}
}
}
catch
{
throw;
}
}
public async Task<List<ProfilePosition>> GetProfileByOrganizationIdAsync(Guid orgId)
{
try
{
var orgProfiles = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x!.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.ThenInclude(x => x!.OrganizationOrganization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Where(x => x.OrganizationPosition!.Organization!.Id == orgId)
.ToListAsync();
return orgProfiles;
}
catch
{
throw;
}
}
public async Task CreateCommandDeploymentAsync(Guid commandId, List<CommandDeployment> deploy)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Deployments)
.FirstOrDefaultAsync(x => x.Id == commandId);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
else
{
var lastSeq = 0;
var dep = command.Deployments.OrderByDescending(x => x.Sequence).FirstOrDefault();
if (dep == null) lastSeq = 1;
else lastSeq = dep.Sequence;
foreach (var dep2 in deploy)
{
dep2.Sequence = lastSeq;
lastSeq++;
}
command.Deployments.AddRange(deploy);
await _dbContext.SaveChangesAsync();
}
}
catch
{
throw;
}
}
public async Task UpdatCommandDeploymentAsync(List<CommandDeployment> deploys)
{
try
{
foreach (var dp in deploys)
{
var updated = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == dp.Id);
if (updated != null)
{
updated.IsSendMail = dp.IsSendMail;
updated.IsSendInbox = dp.IsSendInbox;
}
}
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task DeleteCommandDeploymentAsync(Guid id)
{
try
{
var deleted = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
throw new Exception(GlobalMessages.DataNotFound);
_dbContext.Set<CommandDeployment>().Remove(deleted);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<CommandDeployment?> GetCommandDeploymentById(Guid id)
{
try
{
var data = await _dbContext.Set<CommandDeployment>().FirstOrDefaultAsync(x => x.Id == id);
return data;
}
catch
{
throw;
}
}
#region " Documents "
public async Task<List<CommandDocument>> GetExistDocument(Guid id, string category)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Documents)
.ThenInclude(x => x.Document)
.FirstOrDefaultAsync(c => c.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
// insert new record to comand Document
var exist = command.Documents.Where(x => x.Category == category).ToList();
return exist;
}
catch
{
throw;
}
}
public async Task UploadDocument(Guid id, string category, CommandDocument document)
{
try
{
var command = await _dbContext.Set<Command>()
.Include(x => x.Documents)
//.ThenInclude(x =>x.Document)
.FirstOrDefaultAsync(c => c.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
// insert new record to comand Document
//var exist = command.Documents.Where(x => x.Category == category).ToList();
//if (exist.Any())
//{
// _dbContext.Set<CommandDocument>().RemoveRange(exist);
// await _dbContext.SaveChangesAsync();
//}
// insert new Record
command.Documents.Add(document);
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<List<CommandDocument>> GetCommandDocumentAsync(Guid id)
{
try
{
var docs = await _dbContext.Set<CommandDocument>()
.Include(x => x.Command)
.Include(x => x.Document)
.Where(x => x.Command.Id == id)
.ToListAsync();
return docs;
}
catch
{
throw;
}
}
#endregion
#region " Change Command Status "
public async Task GotoNextStateAsync(Guid id)
{
try
{
var command = await _dbContext.Set<Command>().Include(c => c.CommandType).Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
var notProcess = new int[] { 4, 5 };
if (!notProcess.Contains(command.CommandStatus.Sequence))
{
var num = command.CommandStatus.Sequence + 1;
// if (command.CommandType.CommandCode == "C-PM-38" && command.CommandStatus.Sequence == 1)
// {
// num = num + 1;
// }
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == num);
command.CommandStatus = nextStatus!;
_dbContext.Attatch(nextStatus!);
await _dbContext.SaveChangesAsync();
}
}
catch
{
throw;
}
}
public async Task GotoPrevStateAsync(Guid id)
{
try
{
var command = await _dbContext.Set<Command>().Include(c => c.CommandStatus).FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
var notProcess = new int[] { 1, 5 };
if (!notProcess.Contains(command.CommandStatus.Sequence))
{
var nextStatus = await _dbContext.Set<CommandStatus>().FirstOrDefaultAsync(c => c.Sequence == command.CommandStatus.Sequence - 1);
command.CommandStatus = nextStatus!;
_dbContext.Attatch(nextStatus!);
await _dbContext.SaveChangesAsync();
}
}
catch
{
throw;
}
}
#endregion
#region " Change Detail Sequence "
#endregion
#region " Placement "
public async Task<PlacementSalaryResponse> GetCommandReceiverSalary(Guid recordId, Double? _Amount, Double? _MouthSalaryAmount, Double? _PositionSalaryAmount)
{
try
{
var cmdReceiver = await _dbContext.Set<CommandReceiver>()
.FirstOrDefaultAsync(x => x.Id == recordId);
double SalaryAmount = 0;
double PositionSalaryAmount = 0;
double MonthSalaryAmount = 0;
if (cmdReceiver == null)
{
return new PlacementSalaryResponse
{
SalaryAmount = _Amount == null ? 0 : _Amount.Value,
PositionSalaryAmount = _MouthSalaryAmount == null ? 0 : _MouthSalaryAmount.Value,
MonthSalaryAmount = _PositionSalaryAmount == null ? 0 : _PositionSalaryAmount.Value,
};
}
var profile = await _dbContext.Set<Profile>()
.Include(x => x.Salaries)
.FirstOrDefaultAsync(p => p.CitizenId == cmdReceiver.CitizenId);
if (profile != null && profile.Salaries != null && profile.Salaries.Count() > 0)
{
SalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value : 0;
PositionSalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount.Value : 0;
MonthSalaryAmount = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount.Value : 0;
}
return new PlacementSalaryResponse
{
SalaryAmount = cmdReceiver.Amount != null && cmdReceiver.Amount != 0 ? cmdReceiver.Amount.Value : SalaryAmount,
PositionSalaryAmount = cmdReceiver.PositionSalaryAmount != null && cmdReceiver.PositionSalaryAmount != 0 ? cmdReceiver.PositionSalaryAmount.Value : PositionSalaryAmount,
MonthSalaryAmount = cmdReceiver.MouthSalaryAmount != null && cmdReceiver.MouthSalaryAmount != 0 ? cmdReceiver.MouthSalaryAmount.Value : MonthSalaryAmount,
};
}
catch
{
throw;
}
}
public async Task<PlacementSalaryResponse> GetPlacementSalaryAsync(Guid placementProfileId)
{
try
{
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(p => p.Id == placementProfileId);
if (placementProfile == null)
throw new Exception($"Invalid placement profile: {placementProfileId}");
var profile = await _dbContext.Set<Profile>()
.Include(x => x.Salaries)
.FirstOrDefaultAsync(p => p.CitizenId == placementProfile.CitizenId);
Double SalaryAmount = 0;
Double PositionSalaryAmount = 0;
Double MonthSalaryAmount = 0;
if (profile != null && profile.Salaries.Count() > 0)
{
SalaryAmount = placementProfile.Amount == null || placementProfile.Amount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value : 0) : 0;
PositionSalaryAmount = placementProfile.PositionSalaryAmount == null || placementProfile.PositionSalaryAmount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount.Value : 0) : 0;
MonthSalaryAmount = placementProfile.MouthSalaryAmount == null || placementProfile.MouthSalaryAmount == 0 ? (profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount != null ? profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().MouthSalaryAmount.Value : 0) : 0;
}
return new PlacementSalaryResponse
{
SalaryAmount = placementProfile.Amount != null && placementProfile.Amount != 0 ? placementProfile.Amount.Value : SalaryAmount,
PositionSalaryAmount = placementProfile.PositionSalaryAmount != null && placementProfile.PositionSalaryAmount != 0 ? placementProfile.PositionSalaryAmount.Value : PositionSalaryAmount,
MonthSalaryAmount = placementProfile.MouthSalaryAmount != null && placementProfile.MouthSalaryAmount != 0 ? placementProfile.MouthSalaryAmount.Value : MonthSalaryAmount,
RemarkHorizontal = placementProfile.RemarkHorizontal,
RemarkVertical = placementProfile.RemarkVertical,
};
}
catch
{
throw;
}
}
public async Task UpdateCommandReceiverSalaryAsync(Guid personalId, UpdatePlacementSalaryRequest req)
{
try
{
var current = await _dbContext.Set<CommandReceiver>()
.FirstOrDefaultAsync(x => x.Id == personalId);
if (current == null)
throw new Exception(GlobalMessages.DataNotFound);
current.Amount = req.SalaryAmount;
current.PositionSalaryAmount = req.PositionSalaryAmount;
current.MouthSalaryAmount = req.MonthSalaryAmount;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task UpdatePlacementSalaryAsync(Guid personalId, UpdatePlacementSalaryRequest req)
{
try
{
var current = await _dbContext.Set<CommandReceiver>()
.FirstOrDefaultAsync(x => x.Id == personalId);
if (current == null)
throw new Exception(GlobalMessages.DataNotFound);
var placementProfile = await _dbContext.Set<PlacementProfile>()
.FirstOrDefaultAsync(p => p.Id == current.RefPlacementProfileId);
if (placementProfile == null)
throw new Exception($"Invalid placement profile: {current.RefPlacementProfileId}");
placementProfile.Amount = req.SalaryAmount;
placementProfile.PositionSalaryAmount = req.PositionSalaryAmount;
placementProfile.MouthSalaryAmount = req.MonthSalaryAmount;
placementProfile.RemarkVertical = req.RemarkVertical;
placementProfile.RemarkHorizontal = req.RemarkHorizontal;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
public async Task<List<PositionPath>> GetPlacementPositionPath(Guid id)
{
try
{
var data = await _dbContext.Set<PlacementProfile>()
.Include(x => x.PositionPath)
.Include(x => x.Placement)
.Where(x => x.Placement!.Id == id)
.Where(x => x.PositionPath != null)
.Select(x => x.PositionPath)
.Distinct()
.ToListAsync();
return data!;
}
catch
{
throw;
}
}
#endregion
#region " Command Info "
public async Task<CommandInfoResponse> GetCommandInfoAsync(Guid id)
{
try
{
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
return new CommandInfoResponse
{
SignDate = command.CommandExcecuteDate.Value,
OrderNo = command.CommandNo,
OrderYear = command.CommandYear,
};
}
catch
{
throw;
}
}
public async Task UpdateCommandInfoAsync(Guid id, string orderNo, string orderYear, DateTime signDate)
{
try
{
var command = await _dbContext.Set<Command>().FirstOrDefaultAsync(x => x.Id == id);
if (command == null)
throw new Exception(GlobalMessages.CommandNotFound);
command.CommandExcecuteDate = signDate;
command.CommandNo = orderNo;
command.CommandYear = orderYear;
await _dbContext.SaveChangesAsync();
}
catch
{
throw;
}
}
#endregion
#region " Organization and Approver "
public async Task<Guid> GetRootOcIdAsync(Guid ocId)
{
try
{
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
.FirstOrDefaultAsync(o => o.Id == ocId);
if (data == null)
throw new Exception(GlobalMessages.OrganizationNotFound);
return data.OrganizationAgencyId == null ? ocId : data.OrganizationAgencyId!.Value;
}
catch
{
throw;
}
}
public async Task<List<KeyValueItemResponse>> GetCommandOrgAsync(string token)
{
try
{
var ret = new List<KeyValueItemResponse>();
ret.Add(new KeyValueItemResponse
{
Id = Guid.Empty,
Name = "กรุงเทพมหานคร"
});
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{UserId}";
var apiResult = GetExternalAPIAsync(apiPath, token ?? "");
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<dynamic>(apiResult.Result);
if (raw != null)
{
if (raw.result!.rootId != null && raw.result!.root != null)
{
ret.Add(new KeyValueItemResponse
{
Id = raw.result!.rootId ?? null,
Name = raw.result!.root ?? null,
});
}
}
}
// var rootOcId = await GetRootOcIdAsync(UserOrganizationId);
// var oc = await _dbContext.Set<OrganizationEntity>()
// .Include(x => x.OrganizationOrganization)
// .Select(x => new KeyValueItemResponse
// {
// Id = x.Id,
// Name = x.OrganizationOrganization!.Name
// })
// .FirstOrDefaultAsync(x => x.Id == rootOcId);
// if (oc != null)
// ret.Add(oc);
return ret;
}
catch
{
throw;
}
}
public async Task<List<OrganizationApproverResponse>> GetOrgApproverAsync(Guid ocId)
{
try
{
if (ocId == Guid.Empty)
return new List<OrganizationApproverResponse>() { new OrganizationApproverResponse { Id = Guid.Empty, Name = "", PositionName = "ปลัดกรุงเทพมหานคร" } };
else
{
//var ret = new List<KeyValueItemResponse>();
var oc = await _dbContext.Set<OrganizationEntity>().Include(x => x.Parent).FirstOrDefaultAsync(x => x.Id == ocId);
var profilePosition = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionExecutive)
.Where(x => x.OrganizationPosition!.Organization!.Id == ocId &&
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
.Select(x => new OrganizationApproverResponse
{
Id = x.Profile!.Id,
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ?
x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name
:
x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name
})
.ToListAsync();
if (profilePosition.Count > 0)
{
return profilePosition;
}
else
{
if (oc != null && oc.Parent != null)
{
var parentProfilePosition = await _dbContext.Set<ProfilePosition>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.Organization)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionPath)
.Include(x => x.OrganizationPosition)
.ThenInclude(x => x!.PositionMaster)
.ThenInclude(x => x!.PositionExecutive)
.Where(x => x.OrganizationPosition!.Organization!.Id == oc.Parent.Id &&
x.OrganizationPosition!.PositionMaster!.IsDirector == true)
.Select(x => new OrganizationApproverResponse
{
Id = x.Profile!.Id,
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}",
PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ?
x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name
:
x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name
})
.ToListAsync();
return parentProfilePosition;
}
else
return new List<OrganizationApproverResponse>();
}
}
}
catch
{
throw;
}
}
#endregion
public async Task<dynamic> GetCommandProfileAsync(string commandType, int year, string? posno)
{
try
{
var data = (from r in await _dbContext.Set<ProfileSalary>()
.Include(x => x.Profile)
.ThenInclude(x => x.Prefix)
.Include(x => x.Profile)
.ThenInclude(x => x.PosNo)
.Include(x => x.Profile)
.ThenInclude(x => x.Position)
.ToListAsync()
where r.CommandTypeName == commandType
where r.CommandNo.Contains((year + 543).ToString())
where posno == null || posno == "" ? r.Id != null : r.CommandNo.Contains(posno)
where r.Profile != null
select new
{
Id = r.Profile.Id,
CitizenId = r.Profile.CitizenId,
FullName = $"{r.Profile.Prefix.Name}{r.Profile.FirstName} {r.Profile.LastName}",
PosNo = r.Profile.PosNo == null ? null : r.Profile.PosNo.Name,
Position = r.Profile.Position == null ? null : r.Profile.Position.Name,
})
.Distinct()
.OrderBy(x => x.CitizenId)
.ToList();
return data;
}
catch
{
throw;
}
}
#endregion
public async Task<dynamic> GetHistoryCommandByProfileAsync(string type, Guid id)
{
try
{
var command = await _dbContext.Set<Command>()
.Where(x => x.CommandType.Category == type.Trim().ToLower())
.Where(x => x.Receivers.Where(x => x.RefPlacementProfileId == id).FirstOrDefault() != null)
.Select(x => new
{
CommandSubject = $"{x.CommandNo}/{Int32.Parse(x.CommandYear) + 543} {x.CommandSubject}",
CreatedAt = x.CreatedAt,
LastUpdatedAt = x.LastUpdatedAt,
})
.ToListAsync();
return command;
}
catch
{
throw;
}
}
/// <summary>
/// </summary>
/// <returns></returns>
public async Task DumpDB(string token = "")
{
try
{
var orgIdSend = new List<Guid>() { Guid.Parse("08dc31bb-0707-4ce0-82fd-7e76903e9fca"), Guid.Parse("08dc30ee-2be8-40d0-81bf-b3f2f52dc0ad") };
var profiles = await _dbContext.Set<Profile>()
.Include(x => x.Prefix)
.Include(x => x.Gender)
// .Include(x => x.PositionLevel)
// .Include(x => x.PositionType)
// .Include(x => x.ChangeNames)
// .Include(x => x.FatherHistory)
// .Include(x => x.MotherHistory)
// .Include(x => x.CoupleHistory)
// .Include(x => x.Childrens)
// .Include(x => x.Educations)
// .Include(x => x.Abilitys)
// .Include(x => x.Disciplines)
// .Include(x => x.Leaves)
// .Include(x => x.Dutys)
// .Include(x => x.Salaries)
// .Include(x => x.Nopaids)
// .Include(x => x.Certificates)
// .Include(x => x.Trainings)
// .Include(x => x.Insignias)
// .Include(x => x.Honors)
// .Include(x => x.Assessments)
// .Include(x => x.Others)
// .Take(10)
.Where(x => orgIdSend.Contains(x.Id))
.ToListAsync();
var _baseAPI = _configuration["API"];
// var _baseAPI = "http://localhost:13001/api/v1";
// create new profile
foreach (var profile in profiles)
{
var apiUrl = $"{_baseAPI}/org/profile/all/dump-db";
// var profileId = string.Empty;
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
// var _res = await client.PostAsJsonAsync(apiUrl, new
// {
// id = profile.Id,
// rank = string.Empty,
// prefix = profile.Prefix != null ? profile.Prefix.Name.ToString() : string.Empty,
// firstName = profile.FirstName,
// lastName = profile.LastName,
// citizenId = profile.CitizenId,
// position = "",
// posLevelId = "",
// posTypeId = "",
// email = string.Empty,
// phone = string.Empty,
// keycloak = profile.KeycloakId,
// isProbation = profile.IsProbation,
// isLeave = profile.IsLeave,
// dateRetire = profile.DateRetire,
// dateAppoint = profile.DateAppoint,
// dateStart = profile.DateStart,
// govAgeAbsent = profile.GovAgeAbsent,
// govAgePlus = profile.GovAgePlus,
// birthDate = profile.BirthDate,
// reasonSameDate = profile.ReasonSameDate,
// ethnicity = profile.Race,
// telephoneNumber = profile.TelephoneNumber,
// nationality = profile.Nationality == null ? string.Empty : profile.Nationality,
// gender = profile.Gender != null ? profile.Gender.Name.ToString() : null,
// relationship = profile.RelationshipId != null
// ? await _dbContext.Set<Relationship>().Where(r => r.Id == profile.RelationshipId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// religion = profile.ReligionId != null
// ? await _dbContext.Set<Religion>().Where(r => r.Id == profile.ReligionId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// bloodGroup = profile.BloodGroupId != null
// ? await _dbContext.Set<BloodGroup>().Where(r => r.Id == profile.BloodGroupId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// registrationAddress = profile.RegistrationAddress,
// registrationProvinceId = profile.RegistrationProvinceId != null
// ? await _dbContext.Set<Province>().Where(r => r.Id == profile.RegistrationProvinceId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// registrationDistrictId = profile.RegistrationDistrictId != null
// ? await _dbContext.Set<District>().Where(r => r.Id == profile.RegistrationDistrictId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// registrationSubDistrictId = profile.RegistrationSubDistrictId != null
// ? await _dbContext.Set<SubDistrict>().Where(r => r.Id == profile.RegistrationSubDistrictId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// registrationZipCode = profile.RegistrationZipCode,
// currentAddress = profile.CurrentAddress,
// currentProvinceId = profile.CurrentProvinceId != null
// ? await _dbContext.Set<Province>().Where(r => r.Id == profile.CurrentProvinceId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// currentDistrictId = profile.CurrentDistrictId != null
// ? await _dbContext.Set<District>().Where(r => r.Id == profile.CurrentDistrictId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// currentSubDistrictId = profile.CurrentSubDistrictId != null
// ? await _dbContext.Set<SubDistrict>().Where(r => r.Id == profile.CurrentSubDistrictId).Select(r => r.Name).FirstOrDefaultAsync()
// : null,
// currentZipCode = profile.CurrentZipCode,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// //ยังไม่ SAVE จริง
// //profileId = JsonConvert.DeserializeObject<PlacementProfileId>(_result).result; /*แบบเก่า*/
// //profileId = JsonConvert.DeserializeAnonymousType(_result, new { result = "" }).result; /*แบบใหม่*/
// }
#region profileData
// if (profile.ChangeNames.Count > 0)
// {
// var apiUrlChgName = $"{_baseAPI}/org/profile/changeName";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var chg in profile.ChangeNames)
// {
// var _res = await client.PostAsJsonAsync(apiUrlChgName, new
// {
// profileId = profileId,
// prefixId = string.Empty, //where in node
// prefix = chg.Prefix,
// firstName = chg.FirstName,
// lastName = chg.LastName,
// status = chg.Status,
// documentId = chg.Document,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.FatherHistory.Count > 0)
// {
// var apiUrlFather = $"{_baseAPI}/org/profile/family/father";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var father in profile.FatherHistory)
// {
// var _res = await client.PostAsJsonAsync(apiUrlFather, new
// {
// profileId = profileId,
// fatherPrefix = father.Prefix,
// fatherFirstName = father.FirstName,
// fatherLastName = father.LastName,
// fatherCareer = father.Career,
// fatherCitizenId = string.Empty,
// fatherLive = true,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.MotherHistory.Count > 0)
// {
// var apiUrlMother = $"{_baseAPI}/org/profile/family/mother";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var mother in profile.MotherHistory)
// {
// var _res = await client.PostAsJsonAsync(apiUrlMother, new
// {
// profileId = profileId,
// motherPrefix = mother.Prefix,
// motherFirstName = mother.FirstName,
// motherLastName = mother.LastName,
// motherCareer = mother.Career,
// motherCitizenId = string.Empty,
// motherLive = true,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.CoupleHistory.Count > 0)
// {
// var apiUrlCouple = $"{_baseAPI}/org/profile/family/couple";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var couple in profile.CoupleHistory)
// {
// var _res = await client.PostAsJsonAsync(apiUrlCouple, new
// {
// profileId = profileId,
// couplePrefix = couple.Prefix,
// coupleFirstName = couple.FirstName,
// coupleLastName = couple.LastName,
// coupleLastNameOld = string.Empty,
// coupleCareer = couple.Career,
// coupleCitizenId = string.Empty,
// coupleLive = true,
// relationship = string.Empty,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Childrens.Count > 0)
// {
// var apiUrlChild = $"{_baseAPI}/org/profile/children";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var children in profile.Childrens)
// {
// var _res = await client.PostAsJsonAsync(apiUrlChild, new
// {
// profileId = profileId,
// childrenCareer = children.ChildrenCareer,
// childrenFirstName = children.ChildrenFirstName,
// childrenLastName = children.ChildrenLastName,
// childrenPrefix = children.ChildrenPrefix,
// childrenLive = true,
// childrenCitizenId = string.Empty,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Educations.Count > 0)
// {
// var apiUrlEdu = $"{_baseAPI}/org/profile/educations";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var edu in profile.Educations)
// {
// var _res = await client.PostAsJsonAsync(apiUrlEdu, new
// {
// profileId = profileId,
// country = edu.Country,
// degree = edu.Degree,
// duration = edu.Duration,
// durationYear = edu.DurationYear,
// field = edu.Field,
// finishDate = edu.FinishDate,
// fundName = edu.FundName,
// gpa = edu.Gpa,
// institute = edu.Institute,
// other = edu.Other,
// startDate = edu.StartDate,
// endDate = edu.EndDate,
// educationLevel = edu.EducationLevel,
// educationLevelId = string.Empty, //where in node
// positionPath = edu.PositionPath,
// positionPathId = string.Empty, //where in node
// isDate = false,
// isEducation = false,
// note = edu.Note,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Abilitys.Count > 0)
// {
// var apiUrlAbility = $"{_baseAPI}/org/profile/ability";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var ability in profile.Abilitys)
// {
// var _res = await client.PostAsJsonAsync(apiUrlAbility, new
// {
// profileId = profileId,
// remark = ability.Remark,
// detail = ability.Detail,
// reference = ability.Reference,
// dateStart = ability.DateStart,
// dateEnd = ability.DateEnd,
// field = ability.Field,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Disciplines.Count > 0)
// {
// var apiUrlDisc = $"{_baseAPI}/org/profile/discipline";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var discipline in profile.Disciplines)
// {
// var _res = await client.PostAsJsonAsync(apiUrlDisc, new
// {
// profileId = profileId,
// date = discipline.Date,
// level = discipline.Level,
// detail = discipline.Detail,
// refCommandDate = discipline.RefCommandDate,
// refCommandNo = discipline.RefCommandNo,
// unStigma = string.Empty,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Leaves.Count > 0)
// {
// var apiUrlLeave = $"{_baseAPI}/org/profile/leave/dump-db";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var leave in profile.Leaves)
// {
// var TypeLeaveName = await _dbContext.Set<ProfileLeave>()
// .Include(x => x.TypeLeave).Where(x => x.Id == leave.Id).Select(x => x.TypeLeave.Name).FirstOrDefaultAsync();
// var _res = await client.PostAsJsonAsync(apiUrlLeave, new
// {
// profileId = profileId,
// leaveTypeId = TypeLeaveName == null ? string.Empty : TypeLeaveName, //where in node
// dateLeaveStart = leave.DateStartLeave,
// dateLeaveEnd = leave.DateEndLeave,
// leaveDays = leave.SumLeave,
// leaveCount = leave.NumLeave,
// totalLeave = leave.TotalLeave,
// status = leave.Status,
// reason = leave.Reason,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Dutys.Count > 0)
// {
// var apiUrlDuty = $"{_baseAPI}/org/profile/duty";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var duty in profile.Dutys)
// {
// var _res = await client.PostAsJsonAsync(apiUrlDuty, new
// {
// profileId = profileId,
// dateStart = duty.DateStart,
// dateEnd = duty.DateEnd,
// detail = duty.Detail,
// reference = duty.Reference,
// refCommandDate = string.Empty,
// refCommandNo = string.Empty,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// var Salaries = await _dbContext.Set<ProfileSalary>()
// .Where(x => x.Profile.Id == profile.Id)
// .ToListAsync();
// if (Salaries.Count > 0)
// {
// var apiUrlSalary = $"{_baseAPI}/org/profile/salary";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var salary in Salaries)
// {
// var _res = await client.PostAsJsonAsync(apiUrlSalary, new
// {
// profileId = profile.Id,
// date = salary.Date,
// amount = salary.Amount,
// positionSalaryAmount = salary.PositionSalaryAmount,
// mouthSalaryAmount = salary.MouthSalaryAmount,
// posNo = salary.PosNoName,
// position = salary.PositionName,
// positionLine = salary.PositionLineName,
// positionPathSide = salary.PositionPathSideName,
// positionExecutive = salary.PositionExecutiveName,
// positionType = salary.PositionTypeName,
// positionLevel = salary.PositionLevelName,
// refCommandNo = salary.RefCommandNo,
// templateDoc = salary.SalaryRef,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Nopaids.Count > 0)
// {
// var apiUrlNopaid = $"{_baseAPI}/org/profile/nopaid";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var nopaid in profile.Nopaids)
// {
// var _res = await client.PostAsJsonAsync(apiUrlNopaid, new
// {
// profileId = profileId,
// date = nopaid.Date,
// detail = nopaid.Detail,
// reference = nopaid.Reference,
// refCommandDate = (DateTime?)null,
// refCommandNo = string.Empty,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Certificates.Count > 0)
// {
// var apiUrlCer = $"{_baseAPI}/org/profile/certificate";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var cer in profile.Certificates)
// {
// var _res = await client.PostAsJsonAsync(apiUrlCer, new
// {
// profileId = profileId,
// expireDate = cer.ExpireDate,
// issueDate = cer.IssueDate,
// certificateNo = cer.CertificateNo,
// certificateType = cer.CertificateType,
// issuer = cer.Issuer,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Trainings.Count > 0)
// {
// var apiUrlTrain = $"{_baseAPI}/org/profile/training";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var train in profile.Trainings)
// {
// var _res = await client.PostAsJsonAsync(apiUrlTrain, new
// {
// profileId = profileId,
// startDate = train.StartDate,
// endDate = train.EndDate,
// numberOrder = train.NumberOrder,
// topic = train.Topic,
// place = train.Place,
// dateOrder = train.DateOrder,
// department = train.StartDate,
// duration = train.Duration,
// name = train.Name,
// yearly = train.Yearly,
// isDate = train.IsDate,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
var Insignias = await _dbContext.Set<ProfileInsignia>()
.Include(x => x.Insignia)
.Where(x => profile.Id == x.ProfileId)
.ToListAsync();
if (Insignias.Count > 0)
{
var apiUrlInsig = $"{_baseAPI}/org/dotnet/insignia/Dumb";
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
foreach (var insignia in Insignias)
{
var _res = await client.PostAsJsonAsync(apiUrlInsig, new
{
profileId = profile.Id,
year = insignia.Year,
no = insignia.No,
volume = insignia.Volume,
section = insignia.Section,
page = insignia.Page,
receiveDate = insignia.ReceiveDate,
insigniaId = insignia.Insignia.Id, //where in node
dateAnnounce = insignia.DateAnnounce,
issue = insignia.Issue,
volumeNo = insignia.VolumeNo,
refCommandDate = insignia.RefCommandDate,
refCommandNo = insignia.RefCommandNo,
note = insignia.Note,
});
var _result = await _res.Content.ReadAsStringAsync();
}
}
}
// var Honor = await _dbContext.Set<ProfileHonor>()
// .Where(x => orgIdSend.Contains(x.ProfileId))
// .ToListAsync();
// if (Honor.Count > 0)
// {
// var apiUrlHonor = $"{_baseAPI}/org/profile/honor";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var honor in profile.Honors)
// {
// var _res = await client.PostAsJsonAsync(apiUrlHonor, new
// {
// profileId = profileId,
// detail = honor.Detail,
// issueDate = honor.IssueDate,
// issuer = honor.Issuer,
// refCommandDate = (DateTime?)null,
// refCommandNo = string.Empty,
// isDate = honor.IsDate,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Assessments.Count > 0)
// {
// var apiUrlAssess = $"{_baseAPI}/org/profile/assessments";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var assess in profile.Assessments)
// {
// var _res = await client.PostAsJsonAsync(apiUrlAssess, new
// {
// profileId = profileId,
// name = assess.Name,
// date = assess.Date,
// point1 = assess.Point1,
// point1Total = assess.Point1Total,
// point2 = assess.Point2,
// point2Total = assess.Point2Total,
// pointSum = assess.PointSum,
// pointSumTotal = assess.PointSumTotal,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
// if (profile.Others.Count > 0)
// {
// var apiUrlOther = $"{_baseAPI}/org/profile/other";
// using (var client = new HttpClient())
// {
// client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
// foreach (var other in profile.Others)
// {
// var _res = await client.PostAsJsonAsync(apiUrlOther, new
// {
// profileId = profileId,
// detail = other.Detail,
// date = other.Date,
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
// }
// }
//profile.PlacementStatus = "CONTAIN";
//await _dbContext.SaveChangesAsync();
#endregion
}
//return "";
}
catch
{
throw;
}
}
}
}