2023-09-11 13:53:53 +07:00
using BMA.EHR.Application.Common.Interfaces ;
2023-09-05 14:43:46 +07:00
using BMA.EHR.Application.Messaging ;
2023-08-04 14:30:10 +07:00
using BMA.EHR.Application.Requests.Commands ;
2023-08-07 14:57:23 +07:00
using BMA.EHR.Application.Responses ;
2023-08-08 15:05:53 +07:00
using BMA.EHR.Domain.Extensions ;
2023-07-28 15:04:26 +07:00
using BMA.EHR.Domain.Models.Commands.Core ;
2023-08-08 15:05:53 +07:00
using BMA.EHR.Domain.Models.HR ;
2024-06-21 14:58:00 +07:00
using BMA.EHR.Domain.Models.Leave.Commons ;
2023-08-04 11:59:02 +07:00
using BMA.EHR.Domain.Models.MetaData ;
2023-08-08 15:05:53 +07:00
using BMA.EHR.Domain.Models.Notifications ;
2023-09-02 19:38:24 +07:00
using BMA.EHR.Domain.Models.OrganizationEmployee ;
2023-07-28 15:04:26 +07:00
using BMA.EHR.Domain.Models.Organizations ;
using BMA.EHR.Domain.Models.Placement ;
2023-08-30 12:05:34 +07:00
using BMA.EHR.Domain.Models.Retirement ;
2023-07-28 15:04:26 +07:00
using BMA.EHR.Domain.Shared ;
using Microsoft.AspNetCore.Http ;
using Microsoft.EntityFrameworkCore ;
2023-09-02 18:19:30 +07:00
using Microsoft.Extensions.Configuration ;
using Newtonsoft.Json ;
using System.Net.Http.Headers ;
2024-01-06 03:00:04 +07:00
using System.Net.Http.Json ;
using System.Net.Http.Json ;
2023-07-28 15:04:26 +07:00
using Command = BMA . EHR . Domain . Models . Commands . Core . Command ;
2023-08-08 15:05:53 +07:00
using Profile = BMA . EHR . Domain . Models . HR . Profile ;
2023-07-28 15:04:26 +07:00
namespace BMA.EHR.Application.Repositories.Commands
{
public class CommandRepository : GenericRepository < Guid , Command >
{
#region " Fields "
private readonly IApplicationDBContext _dbContext ;
private readonly IHttpContextAccessor _httpContextAccessor ;
2023-08-08 15:05:53 +07:00
private readonly OrganizationCommonRepository _organizationCommonRepository ;
2023-08-17 12:43:47 +07:00
private readonly UserProfileRepository _userProfileRepository ;
2023-09-02 18:19:30 +07:00
private readonly IConfiguration _configuration ;
2023-09-05 14:43:46 +07:00
private readonly EmailSenderService _emailSenderService ;
2023-07-28 15:04:26 +07:00
#endregion
#region " Constructor and Destuctor "
public CommandRepository ( IApplicationDBContext dbContext ,
2023-08-08 15:05:53 +07:00
IHttpContextAccessor httpContextAccessor ,
2023-08-17 12:43:47 +07:00
OrganizationCommonRepository organizationCommonRepository ,
2023-09-02 18:19:30 +07:00
UserProfileRepository userProfileRepository ,
2023-09-05 14:43:46 +07:00
IConfiguration configuration ,
EmailSenderService emailSenderService ) : base ( dbContext , httpContextAccessor )
2023-07-28 15:04:26 +07:00
{
_dbContext = dbContext ;
_httpContextAccessor = httpContextAccessor ;
2023-08-08 15:05:53 +07:00
_organizationCommonRepository = organizationCommonRepository ;
2023-08-17 12:43:47 +07:00
_userProfileRepository = userProfileRepository ;
2023-09-02 18:19:30 +07:00
_configuration = configuration ;
2023-09-05 14:43:46 +07:00
_emailSenderService = emailSenderService ;
2023-08-17 12:43:47 +07:00
}
#endregion
#region " Properties "
protected Guid UserOrganizationId
{
get
{
if ( UserId ! = null | | UserId ! = "" )
2024-06-20 13:37:25 +07:00
return _userProfileRepository . GetUserOCId ( Guid . Parse ( UserId ! ) , AccessToken ) ;
2023-08-17 12:43:47 +07:00
else
return Guid . Empty ;
}
2023-07-28 15:04:26 +07:00
}
#endregion
#region " Methods "
2023-10-15 14:48:54 +07:00
public void SendMail ( )
{
2023-10-16 17:54:38 +07:00
_emailSenderService . SendMail ( "Test Send Email" , "ทดสอบส่งเมล์" , "suphonchai.ph@gmail.com" ) ;
2023-10-15 14:48:54 +07:00
}
2023-08-07 14:57:23 +07:00
#region " Private "
2023-08-08 10:35:48 +07:00
#region " List Receiver "
2023-09-02 18:19:30 +07:00
public async Task < List < CommandReceiver > > GetReceiverForByCommndTypeAsync ( Command command , string token = "" )
2023-08-07 14:57:23 +07:00
{
2023-08-08 10:19:35 +07:00
var result = new List < CommandReceiver > ( ) ;
switch ( command . CommandType . CommandCode . Trim ( ) . ToUpper ( ) )
2023-08-07 14:57:23 +07:00
{
case "C-PM-01" :
2023-08-08 12:37:02 +07:00
result = await GetReceiver01Async ( command ) ;
2023-08-07 14:57:23 +07:00
break ;
2023-08-28 16:18:35 +07:00
case "C-PM-02" :
result = await GetReceiver02Async ( command ) ;
break ;
2023-08-28 16:44:31 +07:00
case "C-PM-03" :
result = await GetReceiver03Async ( command ) ;
break ;
case "C-PM-04" :
result = await GetReceiver04Async ( command ) ;
break ;
2023-08-30 12:05:34 +07:00
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 ;
2023-09-02 18:19:30 +07:00
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 ;
2023-08-30 12:05:34 +07:00
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" :
2023-12-23 13:48:56 +07:00
result = await GetReceiver19Async ( command , token ) ;
2023-08-30 12:05:34 +07:00
break ;
case "C-PM-20" :
2023-12-23 13:48:56 +07:00
result = await GetReceiver20Async ( command , token ) ;
2023-08-30 12:05:34 +07:00
break ;
2023-09-02 19:38:24 +07:00
case "C-PM-21" :
2024-06-14 17:26:15 +07:00
result = await GetReceiver21Async ( command , token ) ;
2023-09-02 19:38:24 +07:00
break ;
2023-10-10 16:14:25 +07:00
case "C-PM-22" :
result = await GetReceiver22Async ( command ) ;
break ;
case "C-PM-23" :
result = await GetReceiver23Async ( command ) ;
break ;
2023-10-27 14:00:04 +07:00
case "C-PM-24" :
result = await GetReceiver24Async ( command ) ;
break ;
2023-12-22 15:29:24 +07:00
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 ;
2024-04-26 10:18:59 +07:00
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 ;
2024-06-28 17:38:58 +07:00
case "C-PM-38" :
result = await GetReceiver38Async ( command , token ) ;
break ;
2023-08-07 14:57:23 +07:00
default : throw new Exception ( GlobalMessages . MethodForCommandTypeNotImplement ) ;
}
2023-08-08 10:19:35 +07:00
return result ;
2023-08-07 14:57:23 +07:00
}
/// <summary>
2023-08-28 16:18:35 +07:00
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
2023-08-07 14:57:23 +07:00
/// </summary>
2023-08-28 16:18:35 +07:00
/// <param name="command">object ของรายการคำสั่ง</param>
2023-08-07 14:57:23 +07:00
/// <returns></returns>
2023-08-08 12:37:02 +07:00
private async Task < List < CommandReceiver > > GetReceiver01Async ( Command command )
2023-08-07 14:57:23 +07:00
{
try
{
2023-08-08 10:19:35 +07:00
var result = new List < CommandReceiver > ( ) ;
2023-08-10 12:54:07 +07:00
// TODO : ต้องมา list คนตามประเภทอีกครั้งนึง
2023-08-08 10:19:35 +07:00
2023-08-07 14:57:23 +07:00
// 1. หารายชื่อที่ถูกเลือกไปแล้ว ในประเภทเดียวกัน
var otherCommandReceivers = await _dbContext . Set < CommandReceiver > ( )
. Include ( x = > x . Command )
. ThenInclude ( x = > x . CommandType )
2023-08-28 16:18:35 +07:00
. Where ( x = > x . Command . CommandType . CommandCode . Trim ( ) . ToUpper ( ) . StartsWith ( "C-PM-01" ) )
2023-08-10 12:54:07 +07:00
. Where ( x = > x . Command . Id ! = command . Id )
2023-08-07 14:57:23 +07:00
. Select ( x = > x . CitizenId )
. ToListAsync ( ) ;
// 2. Query
var appointPeople = await _dbContext . Set < PlacementProfile > ( )
2023-08-28 16:18:35 +07:00
. Include ( x = > x . Placement )
. ThenInclude ( x = > x . PlacementType )
2023-09-08 11:31:56 +07:00
. Where ( x = > x . Placement . Id = = command . Placement . Id )
2023-08-07 14:57:23 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . CitizenId ! ) )
. Where ( x = > x . PlacementStatus . Trim ( ) . ToUpper ( ) = = "PREPARE-CONTAIN" )
. Where ( x = > x . Draft ! = = true )
2023-08-28 16:18:35 +07:00
. Where ( x = > x . Placement ! . PlacementType ! . Name = = "สอบแข่งขัน" )
2024-07-01 16:11:19 +07:00
. Where ( x = > x . typeCommand . Trim ( ) . ToUpper ( ) = = "APPOINTED" )
2023-08-07 14:57:23 +07:00
. OrderBy ( x = > x . ExamNumber )
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
2024-06-14 17:26:15 +07:00
var receiver = new CommandReceiver
2023-08-28 16:18:35 +07:00
{
2024-06-14 17:26:15 +07:00
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 ) ;
2023-08-28 16:18:35 +07:00
}
return result ;
}
catch
{
throw ;
}
}
2023-08-07 14:57:23 +07:00
2023-08-28 16:18:35 +07:00
/// <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 )
2023-09-08 11:31:56 +07:00
. Where ( x = > x . Placement . Id = = command . Placement . Id )
2023-08-28 16:18:35 +07:00
. 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 ! = "สอบแข่งขัน" )
2024-07-01 16:11:19 +07:00
. Where ( x = > x . typeCommand . Trim ( ) . ToUpper ( ) = = "APPOINTED" )
2023-08-28 16:18:35 +07:00
. OrderBy ( x = > x . ExamNumber )
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
2024-06-14 17:26:15 +07:00
var receiver = new CommandReceiver
2023-08-07 14:57:23 +07:00
{
2024-06-14 17:26:15 +07:00
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 + + ;
2023-08-28 16:18:35 +07:00
2024-06-14 17:26:15 +07:00
result . Add ( receiver ) ;
2023-08-07 14:57:23 +07:00
}
2023-08-08 10:19:35 +07:00
return result ;
2023-08-07 14:57:23 +07:00
}
catch
{
throw ;
}
}
2023-08-28 16:44:31 +07:00
/// <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 )
2024-06-24 09:33:18 +07:00
. ThenInclude ( x = > x . PlacementType )
2023-09-08 11:31:56 +07:00
. Where ( x = > x . Placement . Id = = command . Placement . Id )
2023-08-28 16:44:31 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . CitizenId ! ) )
. Where ( x = > x . PlacementStatus . Trim ( ) . ToUpper ( ) = = "PREPARE-CONTAIN" )
2024-07-01 16:11:19 +07:00
. Where ( x = > x . typeCommand . Trim ( ) . ToUpper ( ) = = "APPOINT" )
2023-08-28 16:44:31 +07:00
. Where ( x = > x . Draft ! = = true )
. OrderBy ( x = > x . ExamNumber )
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
2024-06-14 17:26:15 +07:00
var receiver = new CommandReceiver
2023-08-28 16:44:31 +07:00
{
2024-06-14 17:26:15 +07:00
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 + + ;
2023-08-28 16:44:31 +07:00
2024-06-14 17:26:15 +07:00
result . Add ( receiver ) ;
2023-08-28 16:44:31 +07:00
}
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 )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Command . CommandType . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-04" )
2023-08-28 16:44:31 +07:00
. Where ( x = > x . Command . Id ! = command . Id )
. Select ( x = > x . CitizenId )
. ToListAsync ( ) ;
// 2. Query
var appointPeople = await _dbContext . Set < PlacementProfile > ( )
. Include ( x = > x . Placement )
2024-06-24 09:33:18 +07:00
. ThenInclude ( x = > x . PlacementType )
2023-09-08 11:31:56 +07:00
. Where ( x = > x . Placement . Id = = command . Placement . Id )
2023-08-28 16:44:31 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . CitizenId ! ) )
. Where ( x = > x . PlacementStatus . Trim ( ) . ToUpper ( ) = = "PREPARE-CONTAIN" )
2024-07-01 16:11:19 +07:00
. Where ( x = > x . typeCommand . Trim ( ) . ToUpper ( ) = = "MOVE" )
2023-08-28 16:44:31 +07:00
. Where ( x = > x . Draft ! = = true )
. OrderBy ( x = > x . ExamNumber )
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
2024-06-14 17:26:15 +07:00
var receiver = new CommandReceiver
2023-08-28 16:44:31 +07:00
{
2024-06-14 17:26:15 +07:00
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 + + ;
2023-08-28 16:44:31 +07:00
2024-06-14 17:26:15 +07:00
result . Add ( receiver ) ;
2023-08-28 16:44:31 +07:00
}
return result ;
}
catch
2023-08-30 12:05:34 +07:00
{
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-06-24 09:33:18 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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
2023-08-31 10:26:53 +07:00
var appointPeople = await _dbContext . Set < PlacementAppointment > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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
2023-09-02 20:43:04 +07:00
var appointPeople = await _dbContext . Set < RetirementOther > ( )
2023-08-30 12:05:34 +07:00
. Include ( x = > x . CommandType )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
. Where ( x = > x . CommandType ! . Id = = command . CommandType ! . Id )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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
2023-09-02 20:43:04 +07:00
var appointPeople = await _dbContext . Set < RetirementOther > ( )
2023-08-30 12:05:34 +07:00
. Include ( x = > x . CommandType )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
. Where ( x = > x . CommandType ! . Id = = command . CommandType ! . Id )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
seq + + ;
result . Add ( receiver ) ;
}
return result ;
}
catch
{
throw ;
}
}
2023-09-02 18:19:30 +07:00
/// <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 ;
// เอาชื่อของกรรมการ ไปหาจากทะเบียนประวัติ
2023-09-02 22:19:13 +07:00
var p1 = ( await _dbContext . Set < Profile > ( )
2023-09-02 18:19:30 +07:00
. 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}"
} )
2023-09-02 22:19:13 +07:00
. ToListAsync ( ) )
. FirstOrDefault ( x = > x . fullName = = command . ChairManFullName ) ;
2023-09-02 18:19:30 +07:00
if ( p1 ! = null )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
CitizenId = p1 . citizenId ! ,
Prefix = p1 . prefix ! ,
FirstName = p1 . firstName ! ,
LastName = p1 . lastName ! ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = p1 . profileId ,
2023-09-02 18:19:30 +07:00
} ;
seq + + ;
result . Add ( receiver ) ;
}
2023-09-02 22:19:13 +07:00
var p2 = ( await _dbContext . Set < Profile > ( )
2023-09-02 18:19:30 +07:00
. 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}"
} )
2023-09-02 22:19:13 +07:00
. ToListAsync ( ) )
. FirstOrDefault ( x = > x . fullName = = command . Member1FullName ) ;
2023-09-02 18:19:30 +07:00
if ( p2 ! = null )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
CitizenId = p2 . citizenId ! ,
Prefix = p2 . prefix ! ,
FirstName = p2 . firstName ! ,
LastName = p2 . lastName ! ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = p2 . profileId ,
2023-09-02 18:19:30 +07:00
} ;
seq + + ;
result . Add ( receiver ) ;
}
2023-09-02 22:19:13 +07:00
var p3 = ( await _dbContext . Set < Profile > ( )
2023-09-02 18:19:30 +07:00
. 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}"
} )
2023-09-02 22:19:13 +07:00
. ToListAsync ( ) )
. FirstOrDefault ( x = > x . fullName = = command . Member2FullName ) ;
2023-09-02 18:19:30 +07:00
if ( p3 ! = null )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
CitizenId = p3 . citizenId ! ,
Prefix = p3 . prefix ! ,
FirstName = p3 . firstName ! ,
LastName = p3 . lastName ! ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = p3 . profileId ,
2023-09-02 18:19:30 +07:00
} ;
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 )
{
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}" ;
using ( var _client = new HttpClient ( ) )
2023-09-02 18:19:30 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-09-02 18:19:30 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2023-09-02 18:19:30 +07:00
} ;
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 )
{
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.person.id}" ;
using ( var _client = new HttpClient ( ) )
2023-09-02 18:19:30 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-09-02 18:19:30 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2023-09-02 18:19:30 +07:00
} ;
seq + + ;
resultData . Add ( receiver ) ;
}
}
}
return resultData ;
}
catch
{
throw ;
}
}
2023-08-30 12:05:34 +07:00
/// <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
2023-08-31 12:13:33 +07:00
var appointPeople = await _dbContext . Set < PlacementTransfer > ( )
2024-05-17 18:12:45 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-17 18:12:45 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-21 19:41:55 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-21 19:41:55 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-08-30 12:05:34 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-08-30 12:05:34 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
seq + + ;
result . Add ( receiver ) ;
}
return result ;
}
catch
{
throw ;
}
}
/// <summary>
/// C-PM-19 - คำสั่งปลดออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2023-12-23 13:48:56 +07:00
private async Task < List < CommandReceiver > > GetReceiver19Async ( Command command , string token )
2023-08-30 12:05:34 +07:00
{
try
{
2023-12-23 13:48:56 +07:00
var resultData = new List < CommandReceiver > ( ) ;
2023-08-30 12:05:34 +07:00
// 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 ! ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-08-30 12:05:34 +07:00
} ;
seq + + ;
2023-12-23 13:48:56 +07:00
resultData . Add ( receiver ) ;
2023-08-30 12:05:34 +07:00
}
2023-12-23 13:48:56 +07:00
var baseAPI = _configuration [ "API" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-23 13:48:56 +07:00
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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-23 13:48:56 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-23 13:48:56 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-23 13:48:56 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2023-12-23 13:48:56 +07:00
Amount = 0 ,
} ;
seq + + ;
resultData . Add ( receiver ) ;
}
}
}
return resultData ;
2023-08-30 12:05:34 +07:00
}
catch
{
throw ;
}
}
/// <summary>
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2023-12-23 13:48:56 +07:00
private async Task < List < CommandReceiver > > GetReceiver20Async ( Command command , string token )
2023-08-30 12:05:34 +07:00
{
try
{
2023-12-23 13:48:56 +07:00
var resultData = new List < CommandReceiver > ( ) ;
2023-08-30 12:05:34 +07:00
// 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 )
2023-09-02 19:38:24 +07:00
. 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 ! ,
2023-10-02 19:51:38 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
2023-09-02 19:38:24 +07:00
} ;
seq + + ;
2023-12-23 13:48:56 +07:00
resultData . Add ( receiver ) ;
2023-09-02 19:38:24 +07:00
}
2023-12-23 13:48:56 +07:00
var baseAPI = _configuration [ "API" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-23 13:48:56 +07:00
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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-23 13:48:56 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-23 13:48:56 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-23 13:48:56 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2023-12-23 13:48:56 +07:00
Amount = 0 ,
} ;
seq + + ;
resultData . Add ( receiver ) ;
}
}
}
return resultData ;
2023-09-02 19:38:24 +07:00
}
catch
{
throw ;
}
}
/// <summary>
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-14 17:26:15 +07:00
private async Task < List < CommandReceiver > > GetReceiver21Async ( Command command , string token )
2023-09-02 19:38:24 +07:00
{
try
{
2024-06-14 17:26:15 +07:00
var resultData = new List < CommandReceiver > ( ) ;
2023-09-02 19:38:24 +07:00
2024-06-14 17:26:15 +07:00
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/org/profile-employee/report" ;
2023-08-30 12:05:34 +07:00
2024-06-14 17:26:15 +07:00
var response = new PassSalaryResponse ( ) ;
using ( var client = new HttpClient ( ) )
2023-08-30 12:05:34 +07:00
{
2024-06-14 17:26:15 +07:00
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 )
2023-08-30 12:05:34 +07:00
{
2024-06-14 17:26:15 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
CitizenId = d . citizenId ,
Prefix = d . prefix = = null ? "" : d . prefix ,
FirstName = d . firstName ,
LastName = d . lastName ,
2024-06-17 15:02:54 +07:00
RefPlacementProfileId = d . id ,
2024-06-14 17:26:15 +07:00
RefDisciplineId = d . id ,
2024-06-18 13:54:19 +07:00
Organization = d . organization ,
PositionName = d . positionName ,
PositionLevel = d . positionLevel ,
PositionType = d . positionType ,
PositionNumber = d . positionNumber ,
BirthDate = d . birthDate ,
2024-06-14 17:26:15 +07:00
} ;
seq + + ;
2023-08-30 12:05:34 +07:00
2024-06-14 17:26:15 +07:00
resultData . Add ( receiver ) ;
}
2023-08-30 12:05:34 +07:00
}
2024-06-14 17:26:15 +07:00
return resultData ;
2023-08-30 12:05:34 +07:00
}
catch
2023-08-28 16:44:31 +07:00
{
throw ;
}
}
2023-08-28 16:18:35 +07:00
2023-10-10 16:14:25 +07:00
/// <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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-10-10 16:14:25 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. Where ( x = > x . type = = "EMPLOYEE" )
. OrderBy ( x = > x . citizenId )
2023-10-10 16:14:25 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-10 16:14:25 +07:00
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 > ( )
2024-05-21 19:41:55 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
2023-10-10 16:14:25 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-21 19:41:55 +07:00
. OrderBy ( x = > x . citizenId )
2023-10-10 16:14:25 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-27 14:00:04 +07:00
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 > ( )
2024-05-02 09:31:38 +07:00
. Where ( x = > ! otherCommandReceivers . Contains ( x . citizenId ) )
. Where ( x = > x . type = = "EMPLOYEE" )
2023-10-27 14:00:04 +07:00
. Where ( x = > x . Status . Trim ( ) . ToUpper ( ) = = "REPORT" )
2024-05-02 09:31:38 +07:00
. OrderBy ( x = > x . citizenId )
2023-10-27 14:00:04 +07:00
. ToListAsync ( ) ;
// 3. Create new Record
var seq = 1 ;
foreach ( var item in appointPeople )
{
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
CitizenId = item . citizenId = = null ? "" : item . citizenId ,
Prefix = item . prefix = = null ? "" : item . prefix ,
FirstName = item . firstName = = null ? "" : item . firstName ,
LastName = item . lastName = = null ? "" : item . lastName ,
2023-10-10 16:14:25 +07:00
RefPlacementProfileId = item . Id ,
Amount = item . AmountOld ,
} ;
seq + + ;
result . Add ( receiver ) ;
}
return result ;
}
catch
{
throw ;
}
}
2023-12-22 15:29:24 +07:00
/// <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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/stop/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-26" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-27" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-28" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-29" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-30" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
var commandType = await _dbContext . Set < CommandType > ( )
2023-12-23 13:48:56 +07:00
. Where ( x = > x . CommandCode . Trim ( ) . ToUpper ( ) = = "C-PM-31" )
2023-12-22 15:29:24 +07:00
. 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 )
{
2024-01-06 03:00:04 +07:00
if ( commandType = = null | | commandType . Id ! = d . commandId )
2023-12-22 15:29:24 +07:00
continue ;
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
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" ] ;
2024-01-15 10:38:28 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/reject/{command.ComplaintId}" ;
2023-12-22 15:29:24 +07:00
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 )
{
2024-06-14 17:26:15 +07:00
var _baseAPI = _configuration [ "API" ] ;
var _apiUrl = $"{_baseAPI}/org/profile/profileid/position/{d.personId}" ;
using ( var _client = new HttpClient ( ) )
2023-12-22 15:29:24 +07:00
{
2024-06-14 17:26:15 +07:00
_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 ;
2023-12-22 15:29:24 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
2024-06-14 17:26:15 +07:00
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 ) ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = d . id ,
2024-06-14 17:26:15 +07:00
Amount = 0 ,
2023-12-22 15:29:24 +07:00
} ;
seq + + ;
resultData . Add ( receiver ) ;
}
}
}
return resultData ;
}
catch
{
throw ;
}
}
2024-04-26 10:18:59 +07:00
/// <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 ,
2024-06-14 17:26:15 +07:00
Prefix = d . prefix = = null ? "" : d . prefix ,
2024-04-26 10:18:59 +07:00
FirstName = d . firstName ,
LastName = d . lastName ,
2024-05-02 09:31:38 +07:00
RefPlacementProfileId = d . profileId = = null ? null : Guid . Parse ( d . profileId ) ,
2024-04-26 10:18:59 +07:00
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 ,
2024-06-14 17:26:15 +07:00
Prefix = d . prefix = = null ? "" : d . prefix ,
2024-04-26 10:18:59 +07:00
FirstName = d . firstName ,
LastName = d . lastName ,
2024-04-26 18:03:45 +07:00
RefPlacementProfileId = d . profileId = = null ? null : Guid . Parse ( d . profileId ) ,
2024-04-26 10:18:59 +07:00
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 ,
2024-06-14 17:26:15 +07:00
Prefix = d . prefix = = null ? "" : d . prefix ,
2024-04-26 10:18:59 +07:00
FirstName = d . firstName ,
LastName = d . lastName ,
2024-04-26 18:03:45 +07:00
RefPlacementProfileId = d . profileId = = null ? null : Guid . Parse ( d . profileId ) ,
2024-04-26 10:18:59 +07:00
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 ,
2024-06-14 17:26:15 +07:00
Prefix = d . prefix = = null ? "" : d . prefix ,
2024-04-26 10:18:59 +07:00
FirstName = d . firstName ,
LastName = d . lastName ,
2024-04-26 18:03:45 +07:00
RefPlacementProfileId = d . profileId = = null ? null : Guid . Parse ( d . profileId ) ,
2024-04-26 10:18:59 +07:00
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 ,
2024-06-14 17:26:15 +07:00
Prefix = d . prefix = = null ? "" : d . prefix ,
2024-04-26 10:18:59 +07:00
FirstName = d . firstName ,
LastName = d . lastName ,
2024-04-26 18:03:45 +07:00
RefPlacementProfileId = d . profileId = = null ? null : Guid . Parse ( d . profileId ) ,
2024-04-26 10:18:59 +07:00
RefDisciplineId = d . id ,
} ;
seq + + ;
resultData . Add ( receiver ) ;
}
}
return resultData ;
}
catch
{
throw ;
}
}
2024-06-28 17:38:58 +07:00
/// <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 ;
}
}
2023-08-07 14:57:23 +07:00
#endregion
2023-08-08 10:35:48 +07:00
#region " Execute and Deploy "
2024-01-06 03:00:04 +07:00
private async Task ExecuteCommandByTypeAsync ( Command command , string token = "" )
2023-08-08 12:37:02 +07:00
{
switch ( command . CommandType . CommandCode . Trim ( ) . ToUpper ( ) )
{
case "C-PM-01" :
case "C-PM-02" :
2024-05-07 14:56:54 +07:00
await ExecuteCommand01_02Async ( command , token ) ;
2023-08-08 12:37:02 +07:00
break ;
2023-09-08 09:36:25 +07:00
case "C-PM-03" :
2024-06-24 09:33:18 +07:00
await ExecuteCommand03Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-04" :
2024-06-24 09:33:18 +07:00
await ExecuteCommand04Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-05" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand05Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-06" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand06Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-07" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand07Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-08" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand08Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
case "C-PM-09" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand09Async ( command , token ) ;
2023-09-08 09:36:25 +07:00
break ;
2023-09-07 09:45:36 +07:00
case "C-PM-10" :
await ExecuteCommand10Async ( command ) ;
break ;
2023-09-05 16:24:24 +07:00
case "C-PM-11" :
2024-06-18 13:28:56 +07:00
await ExecuteCommand11Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
case "C-PM-12" :
2024-06-18 13:28:56 +07:00
await ExecuteCommand12Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
2023-09-07 16:26:43 +07:00
case "C-PM-13" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand13Async ( command , token ) ;
2023-09-07 16:26:43 +07:00
break ;
2023-09-08 15:14:39 +07:00
case "C-PM-14" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand14Async ( command , token ) ;
2023-09-08 15:14:39 +07:00
break ;
2023-09-07 09:45:36 +07:00
case "C-PM-15" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand15Async ( command , token ) ;
2023-09-07 09:45:36 +07:00
break ;
case "C-PM-16" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand16Async ( command , token ) ;
2023-09-07 09:45:36 +07:00
break ;
2023-09-05 16:24:24 +07:00
case "C-PM-17" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand17Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
case "C-PM-18" :
2024-06-07 03:06:11 +07:00
await ExecuteCommand18Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
case "C-PM-19" :
2024-01-06 03:00:04 +07:00
await ExecuteCommand19Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
case "C-PM-20" :
2024-01-06 03:00:04 +07:00
await ExecuteCommand20Async ( command , token ) ;
2023-09-05 16:24:24 +07:00
break ;
2023-09-08 15:14:39 +07:00
case "C-PM-21" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand21Async ( command , token ) ;
2023-09-08 15:14:39 +07:00
break ;
2023-10-11 14:07:01 +07:00
case "C-PM-22" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand22Async ( command , token ) ;
2023-10-11 14:07:01 +07:00
break ;
case "C-PM-23" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand23Async ( command , token ) ;
2023-10-11 14:07:01 +07:00
break ;
2023-10-30 20:36:53 +07:00
case "C-PM-24" :
2024-06-14 17:26:15 +07:00
await ExecuteCommand24Async ( command , token ) ;
2023-10-30 20:36:53 +07:00
break ;
2024-01-06 03:00:04 +07:00
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 ;
2024-04-26 10:18:59 +07:00
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 ;
2024-06-28 17:38:58 +07:00
case "C-PM-38" :
await ExecuteCommand38Async ( command , token ) ;
break ;
2023-08-08 12:37:02 +07:00
default : throw new Exception ( GlobalMessages . MethodForCommandTypeNotImplement ) ;
}
}
2023-09-08 09:36:25 +07:00
/// <summary>
/// C-PM-01 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้,
/// C-PM-02 - คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-05-16 17:00:47 +07:00
private async Task ExecuteCommand01_02Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
// create new profile
foreach ( var recv in command . Receivers )
{
// query placement Profile
var placementProfile = await _dbContext . Set < PlacementProfile > ( )
2023-10-11 12:10:01 +07:00
. Include ( x = > x . PlacementProfileDocs )
. ThenInclude ( x = > x . Document )
2023-09-08 09:36:25 +07:00
. 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 ) ;
2024-05-07 14:56:54 +07:00
/*ข้อมูล Profile ใหม่*/
var apiUrl = $"{_configuration[" API "]}/org/profile/all" ;
var profileId = string . Empty ;
using ( var client = new HttpClient ( ) )
2023-09-08 09:36:25 +07:00
{
2024-05-07 14:56:54 +07:00
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 ,
2024-05-16 17:00:47 +07:00
prefix = placementProfile . Prefix = = null ? string . Empty : placementProfile . Prefix ,
2024-05-07 14:56:54 +07:00
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 ,
2024-06-20 18:18:35 +07:00
isProbation = true ,
2024-05-07 14:56:54 +07:00
isLeave = false ,
dateRetire = ( DateTime ? ) null ,
2024-06-26 23:28:27 +07:00
dateAppoint = command . CommandAffectDate = = null ? null : command . CommandAffectDate ,
2024-06-25 09:27:34 +07:00
dateStart = command . CommandAffectDate = = null ? null : command . CommandAffectDate ,
2024-05-07 14:56:54 +07:00
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 ,
2024-05-16 17:00:47 +07:00
gender = placementProfile . Gender = = null ? string . Empty : placementProfile . Gender ,
relationship = placementProfile . Relationship = = null ? string . Empty : placementProfile . Relationship ,
religion = placementProfile . Religion = = null ? string . Empty : placementProfile . Religion ,
2024-05-07 14:56:54 +07:00
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 ;
}
2023-09-08 09:36:25 +07:00
2024-05-07 14:56:54 +07:00
if ( placementProfile . PlacementEducations ! = null )
2023-09-08 09:36:25 +07:00
{
2024-05-07 14:56:54 +07:00
var apiUrlEdu = $"{_configuration[" API "]}/org/profile/educations" ;
using ( var client = new HttpClient ( ) )
2023-09-08 09:36:25 +07:00
{
2024-05-07 14:56:54 +07:00
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 ( ) ;
}
}
2023-09-08 09:36:25 +07:00
}
2024-05-07 14:56:54 +07:00
if ( placementProfile . PlacementCertificates ! = null )
2023-09-08 09:36:25 +07:00
{
2024-05-07 14:56:54 +07:00
var apiUrlCer = $"{_configuration[" API "]}/org/profile/certificate" ;
using ( var client = new HttpClient ( ) )
2023-09-08 09:36:25 +07:00
{
2024-05-07 14:56:54 +07:00
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 ( ) ;
}
}
2023-09-08 09:36:25 +07:00
}
2024-05-07 14:56:54 +07:00
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 ,
2024-06-25 09:27:34 +07:00
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}" : "" ,
2024-05-07 14:56:54 +07:00
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 ,
2024-06-25 09:27:34 +07:00
positionLevel = placementProfile . posLevelName = = null ? string . Empty : placementProfile . posLevelName ,
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-05-07 14:56:54 +07:00
templateDoc = string . Empty ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
profileId = profileId ,
2024-06-24 09:33:18 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
// update placementstatus
placementProfile . PlacementStatus = "CONTAIN" ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = Guid . Parse ( profileId ) ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
}
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
}
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 09:36:25 +07:00
}
catch
{
throw ;
}
}
// <summary>
/// C-PM-03 - คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-24 09:33:18 +07:00
private async Task ExecuteCommand03Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
foreach ( var recv in command . Receivers )
{
var placementProfile = await _dbContext . Set < PlacementProfile > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2024-06-24 09:33:18 +07:00
var baseAPI = _configuration [ "API" ] ;
var apiUrlSalary = $"{baseAPI}/org/profile/salary" ;
using ( var client = new HttpClient ( ) )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-07-04 18:52:21 +07:00
salaryRef = "คำสั่งแต่งตั้ง คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
var baseAPIOrg = _configuration [ "API" ] ;
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current" ;
using ( var client = new HttpClient ( ) )
2023-10-12 05:43:22 +07:00
{
2024-06-24 09:33:18 +07:00
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Replace ( "Bearer " , "" ) ) ;
var _req = new HttpRequestMessage ( HttpMethod . Post , apiUrlOrg ) ;
var _res = await client . PostAsJsonAsync ( apiUrlOrg , new
2023-10-12 05:43:22 +07:00
{
2024-06-24 09:33:18 +07:00
posmasterId = placementProfile . posmasterId ,
positionId = placementProfile . positionId ,
profileId = placementProfile . profileId ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
2023-10-12 05:43:22 +07:00
}
2023-09-08 09:36:25 +07:00
// 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()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( placementProfile . profileId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( placementProfile . profileId ) ,
2023-09-11 13:53:53 +07:00
Type = "LINK" ,
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 09:36:25 +07:00
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
}
// 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>
2024-06-24 09:33:18 +07:00
private async Task ExecuteCommand04Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
foreach ( var recv in command . Receivers )
{
var placementProfile = await _dbContext . Set < PlacementProfile > ( )
2024-06-24 09:33:18 +07:00
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2023-09-08 09:36:25 +07:00
2024-06-24 09:33:18 +07:00
var baseAPI = _configuration [ "API" ] ;
var apiUrlSalary = $"{baseAPI}/org/profile/salary" ;
using ( var client = new HttpClient ( ) )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-07-04 18:52:21 +07:00
salaryRef = "คำสั่งย้าย คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
var baseAPIOrg = _configuration [ "API" ] ;
var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current" ;
using ( var client = new HttpClient ( ) )
2023-10-12 05:43:22 +07:00
{
2024-06-24 09:33:18 +07:00
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token . Replace ( "Bearer " , "" ) ) ;
var _req = new HttpRequestMessage ( HttpMethod . Post , apiUrlOrg ) ;
var _res = await client . PostAsJsonAsync ( apiUrlOrg , new
2023-10-12 05:43:22 +07:00
{
2024-06-24 09:33:18 +07:00
posmasterId = placementProfile . posmasterId ,
positionId = placementProfile . positionId ,
profileId = placementProfile . profileId ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
2023-10-12 05:43:22 +07:00
}
2023-09-08 09:36:25 +07:00
// 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()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( placementProfile . profileId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
var noti = new Notification
{
Body = $"คำสั่งย้าย เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( placementProfile . profileId ) ,
2023-09-11 13:53:53 +07:00
Type = "LINK" ,
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 09:36:25 +07:00
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand05Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
foreach ( var recv in command . Receivers )
{
var placementProfile = await _dbContext . Set < PlacementAppointment > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2024-05-02 09:31:38 +07:00
if ( placementProfile = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = placementProfile . position ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = placementProfile . posTypeName ,
positionLevel = placementProfile . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งแต่งตั้ง คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2023-10-12 05:43:22 +07:00
2023-09-08 09:36:25 +07:00
// update placementstatus
placementProfile . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คำสั่งแต่งตั้ง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 09:36:25 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 09:36:25 +07:00
Body = $"คำสั่งแต่งตั้ง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand06Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
foreach ( var recv in command . Receivers )
{
var placementProfile = await _dbContext . Set < PlacementAppointment > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2024-05-02 09:31:38 +07:00
if ( placementProfile = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = placementProfile . position ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = placementProfile . posTypeName ,
positionLevel = placementProfile . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งเลื่อน คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2023-10-12 05:43:22 +07:00
2023-09-08 09:36:25 +07:00
// update placementstatus
placementProfile . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 09:36:25 +07:00
Body = $"คำสั่งเลื่อน คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand07Async ( Command command , string token = "" )
2023-09-08 09:36:25 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 09:36:25 +07:00
foreach ( var recv in command . Receivers )
{
2024-05-02 09:31:38 +07:00
var placementProfile = await _dbContext . Set < PlacementAppointment > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2023-09-08 09:36:25 +07:00
2024-05-02 09:31:38 +07:00
if ( placementProfile = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = placementProfile . position ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = placementProfile . posTypeName ,
positionLevel = placementProfile . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งย้าย คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2023-09-08 09:36:25 +07:00
2024-05-02 09:31:38 +07:00
// update placementstatus
placementProfile . Status = "DONE" ;
2023-09-08 09:36:25 +07:00
await _dbContext . SaveChangesAsync ( ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 09:36:25 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 09:36:25 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งย้าย คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 09:36:25 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 09:36:25 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 09:36:25 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
// <summary>
2024-05-02 09:31:38 +07:00
/// C-PM-08 - คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
2023-08-28 16:18:35 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand08Async ( Command command , string token = "" )
2023-08-08 12:37:02 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-08-08 15:05:53 +07:00
foreach ( var recv in command . Receivers )
{
2023-09-08 09:36:25 +07:00
var placementProfile = await _dbContext . Set < RetirementOther > ( )
2023-08-08 15:05:53 +07:00
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2024-05-02 09:31:38 +07:00
if ( placementProfile = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
posNo = placementProfile . PositionNumberOld ,
2024-06-07 03:06:11 +07:00
position = placementProfile . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
2024-06-14 17:26:15 +07:00
positionType = placementProfile . PositionTypeOld ,
positionLevel = placementProfile . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-10-17 10:28:25 +07:00
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
dateLeave = _null ,
2024-06-24 09:33:18 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-10-12 05:43:22 +07:00
2023-08-08 15:05:53 +07:00
// update placementstatus
2023-09-08 09:36:25 +07:00
placementProfile . Status = "DONE" ;
2023-08-08 15:05:53 +07:00
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2023-08-08 15:05:53 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-08-08 15:05:53 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-05 16:24:24 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-05 16:24:24 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-09-07 09:45:36 +07:00
// <summary>
2024-05-02 09:31:38 +07:00
/// C-PM-09 - คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
2023-09-07 09:45:36 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand09Async ( Command command , string token = "" )
2023-09-07 09:45:36 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-07 09:45:36 +07:00
foreach ( var recv in command . Receivers )
{
2024-05-02 09:31:38 +07:00
var placementProfile = await _dbContext . Set < RetirementOther > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
if ( placementProfile = = null )
2023-09-07 09:45:36 +07:00
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
posNo = placementProfile . PositionNumberOld ,
2024-06-07 03:06:11 +07:00
position = placementProfile . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
2024-06-14 17:26:15 +07:00
positionType = placementProfile . PositionTypeOld ,
positionLevel = placementProfile . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-07 09:45:36 +07:00
2024-06-24 09:33:18 +07:00
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 ,
2024-06-25 09:27:34 +07:00
dateLeave = _null ,
2024-06-24 09:33:18 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-05-02 09:31:38 +07:00
// update placementstatus
placementProfile . Status = "DONE" ;
2023-09-07 09:45:36 +07:00
await _dbContext . SaveChangesAsync ( ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2023-09-07 09:45:36 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-07 09:45:36 +07:00
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2023-09-07 09:45:36 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-07 09:45:36 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2024-05-02 09:31:38 +07:00
// <summary>
/// C-PM-10 - คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
2023-09-05 16:24:24 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-05-02 09:31:38 +07:00
private async Task ExecuteCommand10Async ( Command command )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
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 ;
2024-01-19 20:47:32 +07:00
if ( lastSarary ! = null & & lastSarary . Order ! = null )
2023-09-05 16:24:24 +07:00
order = lastSarary . Order . Value + 1 ;
var salary = new ProfileSalary
{
Order = order ,
Date = command . CommandAffectDate ,
2024-01-19 20:47:32 +07:00
Amount = lastSarary = = null ? null : lastSarary . Amount ,
PositionSalaryAmount = lastSarary = = null ? null : lastSarary . PositionSalaryAmount ,
MouthSalaryAmount = lastSarary = = null ? null : lastSarary . MouthSalaryAmount ,
2023-09-05 16:24:24 +07:00
SalaryClass = "" ,
2024-05-02 09:31:38 +07:00
SalaryRef = "คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
2023-09-05 16:24:24 +07:00
2024-01-19 20:47:32 +07:00
OcId = lastSarary = = null ? null : lastSarary . OcId ,
2023-09-05 16:24:24 +07:00
2024-01-19 20:47:32 +07:00
PositionId = lastSarary = = null ? null : lastSarary . PositionId ,
2023-09-05 16:24:24 +07:00
2024-01-19 20:47:32 +07:00
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 ,
2023-09-05 16:24:24 +07:00
CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2023-10-11 23:25:54 +07:00
RefCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2023-09-05 16:24:24 +07:00
CommandTypeName = command . CommandType . Name ,
PositionEmployeeGroupId = null ,
PositionEmployeeLevelId = null ,
PositionEmployeePositionId = null ,
PositionEmployeePositionSideId = null ,
PosNoEmployee = "" ,
2024-01-19 20:47:32 +07:00
//PositionPathSideId = lastSarary == null ? null : lastSarary.PositionPathSideId == null,
PositionExecutiveId = lastSarary = = null ? null : lastSarary . PositionExecutiveId ,
//PositionExecutiveSideId = lastSarary == null ? null : lastSarary.PositionExecutiveSideId,
2023-09-05 16:24:24 +07:00
IsActive = true ,
CreatedAt = DateTime . Now ,
CreatedFullName = FullName ? ? "System Administrator" ,
CreatedUserId = UserId ? ? "" ,
LastUpdatedAt = DateTime . Now ,
LastUpdateFullName = FullName ? ? "System Administrator" ,
LastUpdateUserId = UserId ? ? "" ,
} ;
2024-01-19 20:47:32 +07:00
if ( lastSarary ! = null & & lastSarary . PositionPathSideId ! = null ) salary . PositionPathSideId = lastSarary . PositionPathSideId ;
if ( lastSarary ! = null & & lastSarary . PositionExecutiveSideId ! = null ) salary . PositionExecutiveSideId = lastSarary . PositionExecutiveSideId ;
2023-09-05 16:24:24 +07:00
data . Salaries . Add ( salary ) ;
// update placementstatus
//data.Status = "DONE";
await _dbContext . SaveChangesAsync ( ) ;
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
2023-09-08 15:14:39 +07:00
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
2024-05-02 09:31:38 +07:00
var body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
2023-09-05 16:24:24 +07:00
_emailSenderService . SendMail ( subject , body , "dev@frappet.com" ) ;
var inbox = new Inbox
{
2023-09-08 15:14:39 +07:00
Subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-05 16:24:24 +07:00
ReceiverUserId = data . Id ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
var noti = new Notification
{
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-05 16:24:24 +07:00
ReceiverUserId = data . Id ,
2023-09-11 13:53:53 +07:00
Type = "LINK" ,
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-05-02 09:31:38 +07:00
Body = $"คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-05 16:24:24 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-05 16:24:24 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-05-02 09:31:38 +07:00
/// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
2023-09-05 16:24:24 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-18 13:28:56 +07:00
private async Task ExecuteCommand11Async ( Command command , string token = "" )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-18 13:28:56 +07:00
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/org/profile/command11/{recv.RefPlacementProfileId}" ;
using ( var client = new HttpClient ( ) )
2023-09-05 16:24:24 +07:00
{
2024-06-18 13:28:56 +07:00
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 ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
// 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();
// }
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
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" ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-18 13:28:56 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-07 09:45:36 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-05-02 09:31:38 +07:00
/// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
2023-09-07 09:45:36 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-18 13:28:56 +07:00
private async Task ExecuteCommand12Async ( Command command , string token = "" )
2023-09-07 09:45:36 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-07 09:45:36 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-18 13:28:56 +07:00
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/org/profile/command12/{recv.RefPlacementProfileId}" ;
using ( var client = new HttpClient ( ) )
2023-09-07 09:45:36 +07:00
{
2024-06-18 13:28:56 +07:00
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 ( ) ;
}
2023-09-07 09:45:36 +07:00
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-06-18 13:28:56 +07:00
2023-09-07 09:45:36 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
2023-09-08 09:36:25 +07:00
}
2023-09-07 09:45:36 +07:00
2023-09-08 15:14:39 +07:00
/// <summary>
2024-05-02 09:31:38 +07:00
/// C-PM-13 - คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
2023-09-08 15:14:39 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand13Async ( Command command , string token = "" )
2023-09-08 15:14:39 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-08 15:14:39 +07:00
foreach ( var recv in command . Receivers )
{
2024-05-02 09:31:38 +07:00
var data = await _dbContext . Set < PlacementTransfer > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
2023-09-08 15:14:39 +07:00
2024-05-02 09:31:38 +07:00
if ( data = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2023-09-08 15:14:39 +07:00
2024-06-07 03:06:11 +07:00
var baseAPI = _configuration [ "API" ] ;
2024-06-24 09:33:18 +07:00
// var apiUrl = $"{baseAPI}/org/profile/leave/{data.profileId}";
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
// 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 = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ",
2024-06-25 09:27:34 +07:00
// dateLeave = command.CommandAffectDate,
2024-06-24 09:33:18 +07:00
// });
// var _result = await _res.Content.ReadAsStringAsync();
// }
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-07 03:06:11 +07:00
posNo = data . PositionNumberOld ,
position = data . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
2024-06-14 17:26:15 +07:00
positionType = data . PositionTypeOld ,
2024-06-07 03:06:11 +07:00
positionLevel = data . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
// 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();
// }
2024-05-17 18:12:45 +07:00
// // update placementstatus
data . Status = "DONE" ;
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-05-02 09:31:38 +07:00
}
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-05-02 09:31:38 +07:00
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand14Async ( Command command , string token = "" )
2024-05-02 09:31:38 +07:00
{
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 ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = placementProfile . position ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = placementProfile . posTypeName ,
positionLevel = placementProfile . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "รับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2024-05-02 09:31:38 +07:00
// update placementstatus
placementProfile . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 15:14:39 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-09-08 15:14:39 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 15:14:39 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 15:14:39 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 15:14:39 +07:00
Body = $"คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 15:14:39 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-08 15:14:39 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 15:14:39 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-09-07 09:45:36 +07:00
/// <summary>
/// C-PM-15 - คำสั่งให้ช่วยราชการ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand15Async ( Command command , string token = "" )
2023-09-07 09:45:36 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-07 09:45:36 +07:00
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 ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-07 03:06:11 +07:00
posNo = data . PositionNumberOld ,
position = data . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
2024-06-14 17:26:15 +07:00
positionType = data . PositionTypeOld ,
2024-06-07 03:06:11 +07:00
positionLevel = data . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งให้ช่วยราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-07 09:45:36 +07:00
2024-06-24 09:33:18 +07:00
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
2024-05-02 09:31:38 +07:00
// {
2024-06-24 09:33:18 +07:00
// 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();
// }
2023-09-07 09:45:36 +07:00
2024-05-02 09:31:38 +07:00
// // update placementstatus
2023-09-07 09:45:36 +07:00
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
2023-09-08 15:14:39 +07:00
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
2023-09-07 09:45:36 +07:00
var body = $"คำสั่งให้ช่วยราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
_emailSenderService . SendMail ( subject , body , "dev@frappet.com" ) ;
2024-06-24 09:33:18 +07:00
if ( data . profileId ! = null )
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-07 09:45:36 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2023-09-07 09:45:36 +07:00
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-07 09:45:36 +07:00
Body = $"คำสั่งให้ช่วยราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-07 09:45:36 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-07 09:45:36 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-07 09:45:36 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand16Async ( Command command , string token = "" )
2023-09-07 09:45:36 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-07 09:45:36 +07:00
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 ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-07 03:06:11 +07:00
posNo = data . PositionNumberOld ,
position = data . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
2024-06-14 17:26:15 +07:00
positionType = data . PositionTypeOld ,
2024-06-07 03:06:11 +07:00
positionLevel = data . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งส่งตัวกลับ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-07 09:45:36 +07:00
2024-06-24 09:33:18 +07:00
// 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();
// }
2023-09-07 09:45:36 +07:00
// update placementstatus
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2023-09-07 09:45:36 +07:00
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-07 09:45:36 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-07 09:45:36 +07:00
Body = $"คำสั่งส่งตัวกลับ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-05 16:24:24 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-05 16:24:24 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand17Async ( Command command , string token = "" )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
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 ) ;
2024-06-07 03:06:11 +07:00
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 = "ลาออกจากราชการ" ,
2024-06-25 09:27:34 +07:00
dateLeave = command . CommandAffectDate ,
2024-06-07 03:06:11 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-07 03:06:11 +07:00
posNo = data . PositionNumberOld ,
position = data . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = data . PositionTypeOld ,
positionLevel = data . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
2024-05-21 19:41:55 +07:00
// {
2024-06-24 09:33:18 +07:00
// 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();
// }
2023-10-12 05:43:22 +07:00
2024-05-21 19:41:55 +07:00
// // update placementstatus
2023-09-05 16:24:24 +07:00
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
// TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่
// Send noti inbox and email
2023-09-08 15:14:39 +07:00
var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
2023-09-05 16:24:24 +07:00
var body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ;
_emailSenderService . SendMail ( subject , body , "dev@frappet.com" ) ;
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
if ( cc . IsSendInbox )
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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" ) ;
}
2023-09-05 16:24:24 +07:00
var noti = new Notification
{
2024-06-24 09:33:18 +07:00
Body = $"คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Type = "LINK" ,
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
_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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand18Async ( Command command , string token = "" )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
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 ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-07-02 22:22:55 +07:00
leaveReason = "ให้ออกจากราชการ" ,
2024-06-25 09:27:34 +07:00
dateLeave = command . CommandAffectDate ,
2024-06-07 03:06:11 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-07 03:06:11 +07:00
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 ,
2024-06-14 17:26:15 +07:00
amount = recv . Amount ,
2024-06-25 09:27:34 +07:00
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-07 03:06:11 +07:00
posNo = data . PositionNumberOld ,
position = data . PositionOld ,
positionLine = "" ,
positionPathSide = "" ,
positionExecutive = "" ,
positionType = data . PositionTypeOld ,
positionLevel = data . PositionLevelOld ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งให้ออกจากราชการ คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-09-05 16:24:24 +07:00
2024-06-24 09:33:18 +07:00
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/pos/report/current";
// using (var client = new HttpClient())
2024-05-02 09:31:38 +07:00
// {
2024-06-24 09:33:18 +07:00
// 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();
// }
2023-10-12 05:43:22 +07:00
2023-09-05 16:24:24 +07:00
// update placementstatus
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-09-05 16:24:24 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-05 16:24:24 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-05 16:24:24 +07:00
Body = $"คำสั่งให้ออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-05 16:24:24 +07:00
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2023-09-05 16:24:24 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-05 16:24:24 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2023-10-12 05:43:22 +07:00
/// C-PM-19 - คำสั่งปลดออกจากราชการ
2023-09-05 16:24:24 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-01-06 03:00:04 +07:00
private async Task ExecuteCommand19Async ( Command command , string token = "" )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-01-06 03:00:04 +07:00
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
var dataSend = command . Receivers . Select ( x = > new
{
PersonId = x . RefPlacementProfileId ,
Id = x . RefDisciplineId ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-06-24 09:33:18 +07:00
} ) ;
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 ( ) ;
}
2024-01-06 03:00:04 +07:00
2023-09-05 16:24:24 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2023-09-05 16:24:24 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2023-10-12 05:43:22 +07:00
/// C-PM-20 - คำสั่งไล่ออกจากราชการ
2023-09-05 16:24:24 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-01-06 03:00:04 +07:00
private async Task ExecuteCommand20Async ( Command command , string token = "" )
2023-09-05 16:24:24 +07:00
{
try
{
2023-09-11 13:53:53 +07:00
// 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 ) ;
2023-09-05 16:24:24 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
var dataSend = command . Receivers . Select ( x = > new
{
2024-07-04 18:52:21 +07:00
personId = x . RefPlacementProfileId ,
id = x . RefDisciplineId ,
commandAffectDate = command . CommandAffectDate ,
commandNo = command . CommandNo ,
commandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-06-24 09:33:18 +07:00
} ) ;
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 ( ) ;
}
2024-06-19 11:21:24 +07:00
2023-09-05 16:24:24 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2023-08-08 15:05:53 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2023-08-08 12:37:02 +07:00
}
catch
{
throw ;
}
}
2023-09-08 15:14:39 +07:00
/// <summary>
/// C-PM-21 - คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
2023-12-23 13:48:56 +07:00
/// <returns></returns>GenerateCommandReportType25_Cover
2024-06-14 17:26:15 +07:00
private async Task ExecuteCommand21Async ( Command command , string token = "" )
2023-09-08 15:14:39 +07:00
{
try
{
2024-06-14 17:26:15 +07:00
var data = command . Receivers . Select ( x = > new
{
2024-06-18 13:54:19 +07:00
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()}" ,
2024-06-14 17:26:15 +07:00
} ) ;
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 ( ) ;
}
2023-09-11 13:53:53 +07:00
// 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
} ;
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-09-11 13:53:53 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
2023-09-08 15:14:39 +07:00
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-09-08 15:14:39 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-09-08 15:14:39 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-09-08 15:14:39 +07:00
Body = $"คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-09-11 13:53:53 +07:00
Payload = payload_str ,
2023-09-08 15:14:39 +07:00
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2023-09-08 15:14:39 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-09-08 15:14:39 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
2023-10-11 14:07:01 +07:00
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2023-10-30 20:36:53 +07:00
/// C-PM-22 - คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน)
2023-10-11 14:07:01 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand22Async ( Command command , string token = "" )
2023-10-11 14:07:01 +07:00
{
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 )
{
2023-10-11 15:10:52 +07:00
var data = await _dbContext . Set < PlacementAppointment > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recv . RefPlacementProfileId ) ;
if ( data = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-25 09:27:34 +07:00
amount = recv . Amount ,
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = data . position ,
positionType = data . posTypeName ,
positionLevel = data . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2023-10-11 15:10:52 +07:00
// update placementstatus
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2023-10-11 14:07:01 +07:00
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-10-11 14:07:01 +07:00
2024-06-24 09:33:18 +07:00
// รอเอาข้อมูลที่ได้มาส่ง 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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-10-11 14:07:01 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-10-11 14:07:01 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-10-11 14:07:01 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-10-30 20:36:53 +07:00
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ปรับระดับชั้นงาน) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-10-11 14:07:01 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-10-11 14:07:01 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-10-11 14:07:01 +07:00
}
// 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>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand23Async ( Command command , string token = "" )
2023-10-11 14:07:01 +07:00
{
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 ) ;
2024-06-07 03:06:11 +07:00
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 ) ;
2024-06-14 17:26:15 +07:00
var _res = await client . PutAsJsonAsync ( apiUrl , new
2024-06-07 03:06:11 +07:00
{
isLeave = true ,
leaveReason = "ลาออกจากราชการ" ,
2024-06-25 09:27:34 +07:00
dateLeave = command . CommandAffectDate ,
2024-06-07 03:06:11 +07:00
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2023-10-11 14:07:01 +07:00
2024-05-21 19:41:55 +07:00
// // update placementstatus
2023-10-11 14:07:01 +07:00
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" ) ;
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-10-11 14:07:01 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
}
// // send cc noti inbox
foreach ( var cc in command . Deployments )
{
if ( cc . IsSendInbox )
2023-10-11 14:07:01 +07:00
{
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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" ) ;
}
2023-10-11 14:07:01 +07:00
var noti = new Notification
{
2024-06-24 09:33:18 +07:00
Body = $"คำสั่งให้ลูกจ้างออกจากราชการ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-10-11 14:07:01 +07:00
Type = "LINK" ,
Payload = payload_str ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
2023-09-08 15:14:39 +07:00
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-08-08 12:37:02 +07:00
2023-10-30 20:36:53 +07:00
/// <summary>
/// C-PM-24 - คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย)
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-06-07 03:06:11 +07:00
private async Task ExecuteCommand24Async ( Command command , string token = "" )
2023-10-30 20:36:53 +07:00
{
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 ) ;
2024-06-07 03:06:11 +07:00
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 ,
2024-06-25 09:27:34 +07:00
amount = recv . Amount ,
positionSalaryAmount = recv . PositionSalaryAmount ,
mouthSalaryAmount = recv . MouthSalaryAmount ,
2024-06-14 17:26:15 +07:00
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}" : "" ,
2024-06-07 03:06:11 +07:00
position = data . position ,
positionType = data . posTypeName ,
positionLevel = data . posLevelName ,
2024-06-25 09:27:34 +07:00
refCommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}" ,
2024-06-07 03:06:11 +07:00
templateDoc = "คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่ง" + command . IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}" ,
} ) ;
var _result = await _res . Content . ReadAsStringAsync ( ) ;
}
2024-06-24 09:33:18 +07:00
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 ( ) ;
}
2023-10-30 20:36:53 +07:00
// update placementstatus
data . Status = "DONE" ;
await _dbContext . SaveChangesAsync ( ) ;
2024-06-24 09:33:18 +07:00
// 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" ) ;
2023-10-30 20:36:53 +07:00
2024-06-24 09:33:18 +07:00
// รอเอาข้อมูลที่ได้มาส่ง 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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-05-02 09:31:38 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
2023-10-30 20:36:53 +07:00
}
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2023-10-30 20:36:53 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2023-10-30 20:36:53 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2023-10-30 20:36:53 +07:00
Body = $"คำสั่งแต่งตั้งลูกจ้างประจำ(ย้าย) คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2023-10-30 20:36:53 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2023-10-30 20:36:53 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2023-10-30 20:36:53 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2024-01-06 03:00:04 +07:00
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-25 - คำสั่งพักจากราชการ
2024-01-06 03:00:04 +07:00
/// </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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-01-06 03:00:04 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-06 03:00:04 +07:00
var res = await client . PostAsJsonAsync ( apiUrl , new { result = data } ) ;
var result = await res . Content . ReadAsStringAsync ( ) ;
}
2024-01-09 12:45:17 +07:00
// 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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-15 10:38:28 +07:00
}
2024-01-09 12:45:17 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-26 - คำสั่งให้ออกจากราชการไว้ก่อน
2024-01-06 03:00:04 +07:00
/// </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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-01-06 03:00:04 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/stop/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-06 03:00:04 +07:00
var res = await client . PostAsJsonAsync ( apiUrl , new { result = data } ) ;
var result = await res . Content . ReadAsStringAsync ( ) ;
}
2024-01-09 12:45:17 +07:00
// 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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
var apiUrl2 = $"{baseAPI}/org/profile/command26/{recv.RefPlacementProfileId}" ;
using ( var client = new HttpClient ( ) )
2024-01-15 10:38:28 +07:00
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-01-15 10:38:28 +07:00
}
// 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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-01-15 10:38:28 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-15 10:38:28 +07:00
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 )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-15 10:38:28 +07:00
}
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
2024-01-15 10:38:28 +07:00
/// <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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ตัดเงินเดือน"
2024-01-15 10:38:28 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-15 10:38:28 +07:00
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 )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-15 10:38:28 +07:00
}
2024-01-09 12:45:17 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-06 03:00:04 +07:00
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-29 - คำสั่งลงโทษ ลดขั้นเงินเดือน
2024-01-06 03:00:04 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-01-15 10:38:28 +07:00
private async Task ExecuteCommand29Async ( Command command , string token = "" )
2024-01-06 03:00:04 +07:00
{
try
{
var data = command . Receivers . Select ( x = > new
{
PersonId = x . RefPlacementProfileId ,
Id = x . RefDisciplineId ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งลงโทษ ลดขั้นเงินเดือน"
2024-01-06 03:00:04 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-06 03:00:04 +07:00
var res = await client . PostAsJsonAsync ( apiUrl , new { result = data } ) ;
var result = await res . Content . ReadAsStringAsync ( ) ;
}
2024-01-09 12:45:17 +07:00
// 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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-15 10:38:28 +07:00
}
2024-01-09 12:45:17 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-30 - คำสั่งเพิ่มโทษ
2024-01-09 12:45:17 +07:00
/// </summary>
/// <param name="command">object ของรายการคำสั่ง</param>
/// <returns></returns>
2024-01-15 10:38:28 +07:00
private async Task ExecuteCommand30Async ( Command command , string token = "" )
2024-01-09 12:45:17 +07:00
{
try
{
var data = command . Receivers . Select ( x = > new
{
PersonId = x . RefPlacementProfileId ,
Id = x . RefDisciplineId ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งเพิ่มโทษ"
2024-01-09 12:45:17 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-09 12:45:17 +07:00
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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
2024-01-09 12:45:17 +07:00
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-15 10:38:28 +07:00
}
2024-01-09 12:45:17 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-31 - คำสั่งงดโทษ
2024-01-06 03:00:04 +07:00
/// </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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งงดโทษ"
2024-01-06 03:00:04 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
2024-01-09 12:45:17 +07:00
var apiUrl = $"{baseAPI}/discipline/result/report/up/resume" ;
2024-01-06 03:00:04 +07:00
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-06 03:00:04 +07:00
var res = await client . PostAsJsonAsync ( apiUrl , new { result = data } ) ;
var result = await res . Content . ReadAsStringAsync ( ) ;
}
2024-01-09 12:45:17 +07:00
// 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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
var apiUrl2 = $"{baseAPI}/org/profile/command31/{recv.RefPlacementProfileId}" ;
using ( var client = new HttpClient ( ) )
2024-01-15 10:38:28 +07:00
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-09 12:45:17 +07:00
}
2024-06-19 11:21:24 +07:00
// send cc noti inbox
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
}
2024-01-09 12:45:17 +07:00
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
/// <summary>
2024-01-15 10:38:28 +07:00
/// C-PM-32 - คำสั่งยุติเรื่อง
2024-01-06 03:00:04 +07:00
/// </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 ,
2024-06-26 23:28:27 +07:00
CommandAffectDate = command . CommandAffectDate ,
CommandNo = command . CommandNo ,
CommandYear = command . CommandYear . ToInteger ( ) . ToThaiYear ( ) ,
Detail = "คำสั่งยุติเรื่อง"
2024-01-06 03:00:04 +07:00
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/discipline/result/report/reject/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-01-06 03:00:04 +07:00
var res = await client . PostAsJsonAsync ( apiUrl , new { result = data } ) ;
var result = await res . Content . ReadAsStringAsync ( ) ;
}
2024-01-09 12:45:17 +07:00
// 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 ) ;
2024-01-15 10:38:28 +07:00
foreach ( var recv in command . Receivers )
{
2024-06-19 11:21:24 +07:00
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 ( ) ;
}
2024-06-24 09:33:18 +07:00
// 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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-01-15 10:38:28 +07:00
}
2024-04-26 10:18:59 +07:00
// 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 ,
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/salary/report/command/33/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-04-26 10:18:59 +07:00
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 ) ;
2024-06-24 09:33:18 +07:00
foreach ( var recv in command . Receivers )
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_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
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-04-26 10:18:59 +07:00
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2024-04-26 10:18:59 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2024-04-26 10:18:59 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-04-26 10:18:59 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-06-24 09:33:18 +07:00
/// C-PM-34 - คำสั่งค่าตอบแทนพิเศษ และผู้ไม่ได้เลื่อน
2024-04-26 10:18:59 +07:00
/// </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 ,
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/salary/report/command/34/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-04-26 10:18:59 +07:00
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 ) ;
2024-06-24 09:33:18 +07:00
foreach ( var recv in command . Receivers )
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_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
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-04-26 10:18:59 +07:00
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2024-04-26 10:18:59 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-04-26 10:18:59 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-04-26 10:18:59 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-06-24 09:33:18 +07:00
/// C-PM-35 - คำสั่งเลื่อนเงินเดือนข้าราชการเกษียณ
2024-04-26 10:18:59 +07:00
/// </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 ,
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/salary/report/command/35/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-04-26 10:18:59 +07:00
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 ) ;
2024-06-24 09:33:18 +07:00
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 ,
} ;
_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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
2024-04-26 10:18:59 +07:00
// send cc noti inbox
foreach ( var cc in command . Deployments )
{
2024-06-24 09:33:18 +07:00
if ( cc . IsSendInbox )
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
var inbox = new Inbox
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-04-26 10:18:59 +07:00
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2024-04-26 10:18:59 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2024-04-26 10:18:59 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-04-26 10:18:59 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-06-24 09:33:18 +07:00
/// C-PM-36 - คำสั่งเลื่อนขั้นค่าจ้าง
2024-04-26 10:18:59 +07:00
/// </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 ,
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/salary/report/command/36/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-04-26 10:18:59 +07:00
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 ) ;
2024-06-24 09:33:18 +07:00
foreach ( var recv in command . Receivers )
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-04-26 10:18:59 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_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
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-04-26 10:18:59 +07:00
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2024-04-26 10:18:59 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2024-04-26 10:18:59 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-04-26 10:18:59 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
/// <summary>
2024-06-24 09:33:18 +07:00
/// C-PM-37 - คำสั่งให้ลูกจ้างประจำได้รับค่าตอบแทนพิเศษ
2024-04-26 10:18:59 +07:00
/// </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 ,
} ) ;
var baseAPI = _configuration [ "API" ] ;
var apiUrl = $"{baseAPI}/salary/report/command/37/resume" ;
using ( var client = new HttpClient ( ) )
{
client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Bearer" , token ) ;
2024-06-14 17:26:15 +07:00
var req = new HttpRequestMessage ( HttpMethod . Post , apiUrl ) ;
2024-04-26 10:18:59 +07:00
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 ) ;
2024-06-24 09:33:18 +07:00
foreach ( var recv in command . Receivers )
2024-04-26 10:18:59 +07:00
{
2024-06-24 09:33:18 +07:00
// 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" ) ;
2024-01-09 12:45:17 +07:00
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Inbox > ( ) . Add ( inbox ) ;
2024-01-09 12:45:17 +07:00
2024-06-24 09:33:18 +07:00
var noti = new Notification
{
Body = $"คุณได้รับคำสั่งยุติเรื่อง เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
ReceiverUserId = recv . RefPlacementProfileId . Value ,
Type = "LINK" ,
Payload = payload_str ,
} ;
_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
2024-01-09 12:45:17 +07:00
{
2024-06-24 09:33:18 +07:00
Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-01-15 10:38:28 +07:00
Body = $"คำสั่งยุติเรื่อง คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}" ,
2024-06-24 09:33:18 +07:00
ReceiverUserId = Guid . Parse ( cc . ReceiveUserId ) ,
2024-01-09 12:45:17 +07:00
Payload = payload_str ,
} ;
2024-06-24 09:33:18 +07:00
_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" ) ;
2024-01-09 12:45:17 +07:00
}
2024-06-24 09:33:18 +07:00
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 ,
} ;
_dbContext . Set < Notification > ( ) . Add ( noti ) ;
2024-01-09 12:45:17 +07:00
}
// change command status
var cmdStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( x = > x . Sequence = = 5 ) ;
command . CommandStatusId = cmdStatus ! . Id ;
await _dbContext . SaveChangesAsync ( ) ;
2024-01-06 03:00:04 +07:00
}
catch
{
throw ;
}
}
2024-06-28 17:38:58 +07:00
/// <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,
// };
// _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,
// };
// _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 ,
} ;
_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 ,
} ;
_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 ;
}
}
2023-10-11 10:09:26 +07:00
#endregion
#region " Regenerate Json File "
2023-08-08 10:35:48 +07:00
#endregion
#endregion
2023-07-28 15:04:26 +07:00
#region " Override "
public override async Task < Command ? > GetByIdAsync ( Guid id )
2023-09-15 17:07:28 +07:00
{
return await _dbContext . Set < Command > ( )
. Include ( x = > x . Placement )
. Include ( x = > x . CommandType )
2023-09-19 16:26:01 +07:00
. Include ( x = > x . Documents )
. ThenInclude ( x = > x . Document ) //--REmove
2023-09-15 17:07:28 +07:00
. Include ( x = > x . Receivers )
. Include ( x = > x . CommandStatus )
. FirstOrDefaultAsync ( x = > x . Id = = id ) ;
}
public async Task < Command ? > GetByIdWithPlacementAsync ( Guid id )
2023-07-28 15:04:26 +07:00
{
return await _dbContext . Set < Command > ( )
. Include ( x = > x . Placement )
. Include ( x = > x . CommandType )
2023-08-04 10:40:09 +07:00
. Include ( x = > x . Documents )
2023-09-11 13:53:53 +07:00
. ThenInclude ( x = > x . Document )
2023-08-04 10:40:09 +07:00
. Include ( x = > x . Receivers )
. Include ( x = > x . CommandStatus )
2023-07-28 15:04:26 +07:00
. FirstOrDefaultAsync ( x = > x . Id = = id ) ;
}
2023-08-04 11:59:02 +07:00
public override async Task < IReadOnlyList < Command > > GetAllAsync ( )
{
return await _dbContext . Set < Command > ( )
. Include ( x = > x . Placement )
. Include ( x = > x . CommandType )
. Include ( x = > x . CommandStatus )
2024-01-09 12:45:17 +07:00
. Include ( x = > x . Receivers )
2023-09-04 11:37:37 +07:00
. OrderBy ( x = > x . CommandType . CommandCode )
. ThenByDescending ( x = > x . CommandAffectDate )
2023-08-04 11:59:02 +07:00
. ToListAsync ( ) ;
}
2023-08-04 09:47:58 +07:00
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 ! ) ;
2023-08-04 10:40:09 +07:00
2023-08-04 09:47:58 +07:00
return await base . AddAsync ( command ) ;
}
2023-08-04 10:40:09 +07:00
public override async Task < Command > UpdateAsync ( Command entity )
{
// attatch
_dbContext . Attatch ( entity . CommandStatus ) ;
_dbContext . Attatch ( entity . CommandType ) ;
2023-08-25 13:46:18 +07:00
if ( entity . Placement ! = null )
_dbContext . Attatch ( entity . Placement ) ;
2023-08-04 10:40:09 +07:00
return await base . UpdateAsync ( entity ) ;
}
2023-07-28 15:04:26 +07:00
#endregion
2023-08-08 15:05:53 +07:00
#region " Execute Command "
2024-01-06 03:00:04 +07:00
public async Task ExecuteCommandAsync ( Guid id , string token = "" )
2023-08-08 15:05:53 +07:00
{
try
{
var command = await _dbContext . Set < Command > ( )
. Include ( x = > x . Receivers )
. Include ( x = > x . Deployments )
. Include ( x = > x . CommandType )
2023-09-11 13:53:53 +07:00
. Include ( x = > x . Documents )
. ThenInclude ( x = > x . Document )
2023-08-08 15:05:53 +07:00
. FirstOrDefaultAsync ( x = > x . Id = = id ) ;
if ( command = = null )
throw new Exception ( GlobalMessages . CommandNotFound ) ;
else
2024-01-06 03:00:04 +07:00
await ExecuteCommandByTypeAsync ( command , token ) ;
2023-08-08 15:05:53 +07:00
}
catch
{
throw ;
}
}
#endregion
2023-08-04 14:30:10 +07:00
#region " Command Receiver "
2023-09-02 21:38:31 +07:00
public async Task SaveSelectedReceiverAsync ( Guid id , List < Guid > selected , string token = "" )
2023-08-08 10:19:35 +07:00
{
try
{
2023-09-15 17:07:28 +07:00
Command command = null ;
var c = await _dbContext . Set < Command > ( )
2023-08-08 10:19:35 +07:00
. Include ( x = > x . CommandType )
. FirstOrDefaultAsync ( x = > x . Id = = id ) ;
2023-09-15 17:07:28 +07:00
if ( c = = null )
2023-08-08 10:19:35 +07:00
throw new Exception ( GlobalMessages . CommandNotFound ) ;
2023-09-15 17:07:28 +07:00
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 ;
default :
command = await _dbContext . Set < Command > ( )
. Include ( x = > x . Receivers )
. Include ( x = > x . CommandType )
. FirstOrDefaultAsync ( x = > x . Id = = id ) ;
break ;
}
2023-09-02 21:38:31 +07:00
var ap = ( await GetReceiverForByCommndTypeAsync ( command , token ) ) . Where ( x = > selected . Contains ( x . RefPlacementProfileId ! . Value ) ) ;
2023-08-31 12:13:33 +07:00
//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();
2023-08-08 10:19:35 +07:00
_dbContext . Set < CommandReceiver > ( ) . RemoveRange ( command . Receivers ) ;
await _dbContext . SaveChangesAsync ( ) ;
var seq = 1 ;
2023-08-31 12:13:33 +07:00
foreach ( var item in ap )
2023-08-08 10:19:35 +07:00
{
2023-09-25 17:06:20 +07:00
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" :
2023-10-11 12:32:27 +07:00
case "C-PM-04" :
2023-09-25 17:06:20 +07:00
salary = await GetPlacementSalaryAsync ( item . RefPlacementProfileId . Value ) ;
break ;
default :
2023-10-11 12:32:27 +07:00
salary = await GetCommandReceiverSalary ( item . RefPlacementProfileId . Value , item . Amount , item . MouthSalaryAmount , item . PositionSalaryAmount ) ;
2023-09-25 17:06:20 +07:00
break ;
}
2023-08-08 10:19:35 +07:00
var receiver = new CommandReceiver
{
Sequence = seq ,
CitizenId = item . CitizenId ! ,
2023-08-31 12:13:33 +07:00
Prefix = item . Prefix ,
FirstName = item . FirstName ! ,
LastName = item . LastName ! ,
2023-09-25 17:06:20 +07:00
RefPlacementProfileId = item . RefPlacementProfileId ,
2024-01-06 03:00:04 +07:00
RefDisciplineId = item . RefDisciplineId ,
2023-09-25 17:06:20 +07:00
Amount = salary = = null ? 0 : salary . SalaryAmount ,
MouthSalaryAmount = salary = = null ? 0 : salary . MonthSalaryAmount ,
2024-06-18 13:54:19 +07:00
PositionSalaryAmount = salary = = null ? 0 : salary . PositionSalaryAmount ,
Organization = item . Organization ,
PositionName = item . PositionName ,
PositionLevel = item . PositionLevel ,
PositionType = item . PositionType ,
PositionNumber = item . PositionNumber ,
BirthDate = item . BirthDate ,
2023-08-08 10:19:35 +07:00
} ;
2023-08-31 12:13:33 +07:00
seq + + ;
2023-08-08 10:19:35 +07:00
command . Receivers . Add ( receiver ) ;
}
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-09-02 18:19:30 +07:00
public async Task < List < CommandReceiver > > GetReceiverForCommandAsync ( Guid id , string token = "" )
2023-08-08 10:19:35 +07:00
{
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
2023-09-02 18:19:30 +07:00
return await GetReceiverForByCommndTypeAsync ( command , token ) ;
2023-08-08 10:19:35 +07:00
}
catch
{
throw ;
}
}
2023-07-28 15:04:26 +07:00
public async Task < List < CommandReceiver > > GetReceiverByCommmandIdAsync ( Guid Id )
{
try
{
2023-08-08 10:19:35 +07:00
// ปรับใหม่ให้อ่านจาก database ล้วนๆ
2023-07-28 15:04:26 +07:00
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
{
2023-08-07 11:53:11 +07:00
if ( command . Receivers ! = null & & command ! . Receivers ! . Count > 0 )
2023-07-28 15:04:26 +07:00
{
return command . Receivers ;
}
else
{
2023-08-08 10:19:35 +07:00
// returrn empty list
return new List < CommandReceiver > ( ) ;
2023-07-28 15:04:26 +07:00
}
}
}
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 ;
}
}
2023-08-04 14:30:10 +07:00
public async Task < CommandReceiver ? > GetCommandReceiverAsync ( Guid personalId )
{
try
{
var receiver = await _dbContext . Set < CommandReceiver > ( )
2023-09-02 13:53:56 +07:00
. Include ( x = > x . Command )
. ThenInclude ( x = > x . CommandType )
2023-08-04 14:30:10 +07:00
. 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 > ( )
2023-08-11 14:05:08 +07:00
. Include ( c = > c . Command )
2023-08-04 14:30:10 +07:00
. FirstOrDefaultAsync ( x = > x . Id = = personalId ) ;
if ( current = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
var currentSeq = current . Sequence ;
2023-08-11 14:05:08 +07:00
var commandID = current . Command ! . Id ;
2023-08-04 14:30:10 +07:00
switch ( direction . Trim ( ) . ToLower ( ) )
{
case "up" :
{
// get prev record
var prev = await _dbContext . Set < CommandReceiver > ( )
2023-08-16 14:15:45 +07:00
. Include ( c = > c . Command )
2023-08-11 14:05:08 +07:00
. Where ( x = > x . Command . Id = = commandID )
2023-08-04 14:30:10 +07:00
. Where ( x = > x . Sequence < currentSeq )
2023-08-16 14:15:45 +07:00
. OrderByDescending ( x = > x . Sequence )
2023-08-04 14:30:10 +07:00
. 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 > ( )
2023-08-11 14:05:08 +07:00
. Include ( c = > c . Command )
. Where ( x = > x . Command . Id = = commandID )
2023-08-04 14:30:10 +07:00
. Where ( x = > x . Sequence > currentSeq )
2023-08-11 14:05:08 +07:00
. OrderBy ( x = > x . Sequence )
2023-08-04 14:30:10 +07:00
. 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
2023-09-25 17:06:20 +07:00
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 > ( )
2024-05-02 09:31:38 +07:00
//.Include(x => x.PositionPath)
2023-09-25 17:06:20 +07:00
on r . RefPlacementProfileId equals pf . Id
where r . Command . Id = = id
select new
{
r . RefPlacementProfileId ,
2024-05-03 17:39:10 +07:00
Position = pf . position
2023-09-25 17:06:20 +07:00
} ) . 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 ;
}
}
2023-07-28 15:04:26 +07:00
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 ;
}
}
2023-07-28 16:30:03 +07:00
#region " Documents "
2023-08-04 11:59:02 +07:00
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
{
2023-08-08 12:37:02 +07:00
var command = await _dbContext . Set < Command > ( )
. Include ( x = > x . Documents )
//.ThenInclude(x =>x.Document)
. FirstOrDefaultAsync ( c = > c . Id = = id ) ;
2023-08-04 11:59:02 +07:00
if ( command = = null )
throw new Exception ( GlobalMessages . CommandNotFound ) ;
// insert new record to comand Document
2023-08-08 12:37:02 +07:00
//var exist = command.Documents.Where(x => x.Category == category).ToList();
//if (exist.Any())
//{
// _dbContext.Set<CommandDocument>().RemoveRange(exist);
// await _dbContext.SaveChangesAsync();
//}
2023-08-04 11:59:02 +07:00
// insert new Record
command . Documents . Add ( document ) ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-07-28 16:30:03 +07:00
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
2023-08-04 10:40:09 +07:00
#region " Change Command Status "
public async Task GotoNextStateAsync ( Guid id )
{
try
{
2024-06-28 17:38:58 +07:00
var command = await _dbContext . Set < Command > ( ) . Include ( c = > c . CommandType ) . Include ( c = > c . CommandStatus ) . FirstOrDefaultAsync ( x = > x . Id = = id ) ;
2023-08-04 10:40:09 +07:00
if ( command = = null )
throw new Exception ( GlobalMessages . CommandNotFound ) ;
var notProcess = new int [ ] { 4 , 5 } ;
if ( ! notProcess . Contains ( command . CommandStatus . Sequence ) )
{
2024-06-28 17:38:58 +07:00
var num = command . CommandStatus . Sequence + 1 ;
2024-06-28 18:21:28 +07:00
// if (command.CommandType.CommandCode == "C-PM-38" && command.CommandStatus.Sequence == 1)
// {
// num = num + 1;
// }
2024-06-28 17:38:58 +07:00
var nextStatus = await _dbContext . Set < CommandStatus > ( ) . FirstOrDefaultAsync ( c = > c . Sequence = = num ) ;
2023-08-04 10:40:09 +07:00
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
2023-08-04 11:59:02 +07:00
#region " Change Detail Sequence "
#endregion
#region " Placement "
2023-10-11 12:32:27 +07:00
public async Task < PlacementSalaryResponse > GetCommandReceiverSalary ( Guid recordId , Double ? _Amount , Double ? _MouthSalaryAmount , Double ? _PositionSalaryAmount )
2023-09-02 13:53:56 +07:00
{
try
{
var cmdReceiver = await _dbContext . Set < CommandReceiver > ( )
. FirstOrDefaultAsync ( x = > x . Id = = recordId ) ;
2023-10-11 12:32:27 +07:00
double SalaryAmount = 0 ;
double PositionSalaryAmount = 0 ;
double MonthSalaryAmount = 0 ;
2023-09-02 13:53:56 +07:00
if ( cmdReceiver = = null )
2023-10-11 12:32:27 +07:00
{
2023-09-02 21:11:42 +07:00
return new PlacementSalaryResponse
{
2023-10-11 12:32:27 +07:00
SalaryAmount = _Amount = = null ? 0 : _Amount . Value ,
PositionSalaryAmount = _MouthSalaryAmount = = null ? 0 : _MouthSalaryAmount . Value ,
MonthSalaryAmount = _PositionSalaryAmount = = null ? 0 : _PositionSalaryAmount . Value ,
2023-09-02 21:11:42 +07:00
} ;
2023-10-11 12:32:27 +07:00
}
2023-09-13 13:11:05 +07:00
var profile = await _dbContext . Set < Profile > ( )
. Include ( x = > x . Salaries )
. FirstOrDefaultAsync ( p = > p . CitizenId = = cmdReceiver . CitizenId ) ;
2023-10-02 19:51:38 +07:00
if ( profile ! = null & & profile . Salaries ! = null & & profile . Salaries . Count ( ) > 0 )
2023-09-13 13:11:05 +07:00
{
2023-10-02 19:51:38 +07:00
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 ;
2023-09-13 13:11:05 +07:00
}
2023-09-02 13:53:56 +07:00
return new PlacementSalaryResponse
{
2023-10-11 12:32:27 +07:00
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 ,
2023-09-02 13:53:56 +07:00
} ;
}
catch
{
throw ;
}
}
2023-08-07 14:57:23 +07:00
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}" ) ;
2023-09-13 13:11:05 +07:00
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 )
{
2023-10-05 10:01:16 +07:00
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 ;
2023-09-13 13:11:05 +07:00
}
2023-08-07 14:57:23 +07:00
return new PlacementSalaryResponse
{
2023-10-02 19:51:38 +07:00
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 ,
2023-10-08 12:41:53 +07:00
RemarkHorizontal = placementProfile . RemarkHorizontal ,
2023-10-09 18:36:44 +07:00
RemarkVertical = placementProfile . RemarkVertical ,
2023-08-07 14:57:23 +07:00
} ;
}
catch
{
throw ;
}
}
2023-09-02 13:53:56 +07:00
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 ;
}
}
2023-08-09 20:28:56 +07:00
public async Task UpdatePlacementSalaryAsync ( Guid personalId , UpdatePlacementSalaryRequest req )
2023-08-04 14:30:10 +07:00
{
try
{
2023-08-09 20:28:56 +07:00
var current = await _dbContext . Set < CommandReceiver > ( )
. FirstOrDefaultAsync ( x = > x . Id = = personalId ) ;
if ( current = = null )
throw new Exception ( GlobalMessages . DataNotFound ) ;
2023-08-04 14:30:10 +07:00
var placementProfile = await _dbContext . Set < PlacementProfile > ( )
2023-08-09 20:28:56 +07:00
. FirstOrDefaultAsync ( p = > p . Id = = current . RefPlacementProfileId ) ;
2023-08-04 14:30:10 +07:00
if ( placementProfile = = null )
2023-08-09 20:28:56 +07:00
throw new Exception ( $"Invalid placement profile: {current.RefPlacementProfileId}" ) ;
2023-08-04 14:30:10 +07:00
placementProfile . Amount = req . SalaryAmount ;
placementProfile . PositionSalaryAmount = req . PositionSalaryAmount ;
placementProfile . MouthSalaryAmount = req . MonthSalaryAmount ;
2023-10-08 12:41:53 +07:00
placementProfile . RemarkVertical = req . RemarkVertical ;
placementProfile . RemarkHorizontal = req . RemarkHorizontal ;
2023-08-04 14:30:10 +07:00
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-08-04 11:59:02 +07:00
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
2023-08-07 14:57:23 +07:00
#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 )
2023-07-28 16:30:03 +07:00
{
try
{
var command = await _dbContext . Set < Command > ( ) . FirstOrDefaultAsync ( x = > x . Id = = id ) ;
2023-08-04 10:40:09 +07:00
if ( command = = null )
2023-07-28 16:30:03 +07:00
throw new Exception ( GlobalMessages . CommandNotFound ) ;
command . CommandExcecuteDate = signDate ;
command . CommandNo = orderNo ;
command . CommandYear = orderYear ;
await _dbContext . SaveChangesAsync ( ) ;
}
catch
{
throw ;
}
}
2023-08-07 14:57:23 +07:00
#endregion
2023-08-07 13:48:29 +07:00
2023-08-17 12:43:47 +07:00
#region " Organization and Approver "
2023-08-07 14:57:23 +07:00
public async Task < Guid > GetRootOcIdAsync ( Guid ocId )
{
try
{
var data = await _dbContext . Set < OrganizationEntity > ( ) . AsQueryable ( )
. FirstOrDefaultAsync ( o = > o . Id = = ocId ) ;
2023-08-07 11:53:11 +07:00
2023-08-07 14:57:23 +07:00
if ( data = = null )
throw new Exception ( GlobalMessages . OrganizationNotFound ) ;
2023-08-07 11:53:11 +07:00
2023-08-18 10:53:44 +07:00
return data . OrganizationAgencyId = = null ? ocId : data . OrganizationAgencyId ! . Value ;
2023-08-07 14:57:23 +07:00
}
catch
{
throw ;
}
}
2023-08-07 11:53:11 +07:00
2024-06-24 09:33:18 +07:00
public async Task < List < KeyValueItemResponse > > GetCommandOrgAsync ( string token )
2023-08-17 12:43:47 +07:00
{
try
{
var ret = new List < KeyValueItemResponse > ( ) ;
ret . Add ( new KeyValueItemResponse
{
Id = Guid . Empty ,
Name = "กรุงเทพมหานคร"
} ) ;
2024-06-24 09:33:18 +07:00
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 )
{
2024-07-05 13:58:00 +07:00
if ( raw . result ! . rootId ! = null & & raw . result ! . root ! = null )
2024-06-24 09:33:18 +07:00
{
2024-07-05 13:58:00 +07:00
ret . Add ( new KeyValueItemResponse
{
Id = raw . result ! . rootId ? ? null ,
Name = raw . result ! . root ? ? null ,
} ) ;
}
2024-06-24 09:33:18 +07:00
}
}
// 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);
2023-08-17 12:43:47 +07:00
return ret ;
}
catch
{
throw ;
}
}
2023-08-18 10:53:44 +07:00
public async Task < List < OrganizationApproverResponse > > GetOrgApproverAsync ( Guid ocId )
2023-08-17 12:43:47 +07:00
{
try
{
if ( ocId = = Guid . Empty )
2023-08-18 10:53:44 +07:00
return new List < OrganizationApproverResponse > ( ) { new OrganizationApproverResponse { Id = Guid . Empty , Name = "" , PositionName = "ปลัดกรุงเทพมหานคร" } } ;
2023-08-17 12:43:47 +07:00
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 )
2023-08-18 10:53:44 +07:00
. ThenInclude ( x = > x ! . PositionPath )
. Include ( x = > x . OrganizationPosition )
. ThenInclude ( x = > x ! . PositionMaster )
. ThenInclude ( x = > x ! . PositionExecutive )
2023-08-17 12:43:47 +07:00
. Where ( x = > x . OrganizationPosition ! . Organization ! . Id = = ocId & &
x . OrganizationPosition ! . PositionMaster ! . IsDirector = = true )
2023-08-18 10:53:44 +07:00
. Select ( x = > new OrganizationApproverResponse
2023-08-17 12:43:47 +07:00
{
Id = x . Profile ! . Id ,
2023-08-18 10:53:44 +07:00
Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}" ,
PositionName = x . OrganizationPosition ! . PositionMaster ! . PositionExecutive ! = null ?
x . OrganizationPosition ! . PositionMaster ! . PositionExecutive ! . Name
2023-08-20 11:07:18 +07:00
:
2023-08-18 10:53:44 +07:00
x . OrganizationPosition ! . PositionMaster ! . PositionPath = = null ? "" : x . OrganizationPosition ! . PositionMaster ! . PositionPath ! . Name
2023-08-17 12:43:47 +07:00
} )
. 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 )
2023-08-18 10:53:44 +07:00
. ThenInclude ( x = > x ! . PositionPath )
. Include ( x = > x . OrganizationPosition )
. ThenInclude ( x = > x ! . PositionMaster )
. ThenInclude ( x = > x ! . PositionExecutive )
2023-08-17 12:43:47 +07:00
. Where ( x = > x . OrganizationPosition ! . Organization ! . Id = = oc . Parent . Id & &
x . OrganizationPosition ! . PositionMaster ! . IsDirector = = true )
2023-08-18 10:53:44 +07:00
. Select ( x = > new OrganizationApproverResponse
2023-08-17 12:43:47 +07:00
{
Id = x . Profile ! . Id ,
2023-08-18 10:53:44 +07:00
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
2023-08-17 12:43:47 +07:00
} )
. ToListAsync ( ) ;
return parentProfilePosition ;
}
else
2023-08-18 10:53:44 +07:00
return new List < OrganizationApproverResponse > ( ) ;
2023-08-17 12:43:47 +07:00
}
}
}
catch
{
throw ;
}
}
#endregion
2023-09-06 11:52:48 +07:00
public async Task < dynamic > GetCommandProfileAsync ( string commandType , int year , string? posno )
2023-09-05 20:24:15 +07:00
{
try
{
2023-09-06 11:52:48 +07:00
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 ;
2023-09-05 20:24:15 +07:00
}
catch
{
throw ;
}
}
2023-09-08 11:31:56 +07:00
2023-07-28 15:04:26 +07:00
#endregion
2024-01-05 09:25:03 +07:00
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
{
2024-01-22 17:20:57 +07:00
CommandSubject = $"{x.CommandNo}/{Int32.Parse(x.CommandYear) + 543} {x.CommandSubject}" ,
2024-01-05 09:25:03 +07:00
CreatedAt = x . CreatedAt ,
LastUpdatedAt = x . LastUpdatedAt ,
} )
. ToListAsync ( ) ;
return command ;
}
catch
{
throw ;
}
}
2024-06-19 14:50:38 +07:00
/// <summary>
/// </summary>
/// <returns></returns>
2024-06-21 14:58:00 +07:00
public async Task DumpDB ( string token = "" )
2024-06-19 14:50:38 +07:00
{
try
{
2024-06-28 17:38:58 +07:00
var orgIdSend = new List < Guid > ( ) { Guid . Parse ( "08dc4c9f-ca39-44dd-8f93-04024aedccbe" ) , Guid . Parse ( "08dc4c9f-b4e7-47ae-8cb9-87b615151ada" ) , Guid . Parse ( "08dc4c9f-9da6-443e-8a72-30b8be40d954" ) , Guid . Parse ( "08dc4c9f-8487-4966-8ca6-11ba71d91971" ) , Guid . Parse ( "08dc4c9f-6e7e-4c75-8996-a48295978eca" ) , Guid . Parse ( "08dc4c9f-4166-4146-8460-f8af7cc8a4f1" ) , Guid . Parse ( "08dc4c9f-2710-4e98-8340-c9f2a65467db" ) , Guid . Parse ( "08dc4c9f-0ef3-4e51-805f-74766c67c1df" ) , Guid . Parse ( "08dc4c9e-f8be-4dae-89ed-30d662a29eed" ) , Guid . Parse ( "08dc4c9e-dd93-4072-8f37-482e7b91da28" ) , Guid . Parse ( "08dc4c9e-30c6-4674-8a35-4275eb70038f" ) , Guid . Parse ( "08dc4c9e-060b-4ae1-8068-bcf59b1d4642" ) , Guid . Parse ( "08dc4c9d-e7a2-4a26-84b8-655fac120ceb" ) , Guid . Parse ( "08dc4c9d-d0fe-4393-8948-d1ef0dece9e3" ) , Guid . Parse ( "08dc4c9d-b930-4be9-8428-82f802f28d99" ) , Guid . Parse ( "08dc4c9d-a10d-49ea-8484-a9646be5f6da" ) , Guid . Parse ( "08dc4c9d-8937-4432-865f-ffd3992feb25" ) , Guid . Parse ( "08dc4c9d-72f7-4f8a-8916-4b1791ca24c8" ) , Guid . Parse ( "08dc4c9d-5993-46b9-8ae8-96c4edbc163d" ) , Guid . Parse ( "08dc4c9d-291b-4761-8013-81027aac3b3d" ) , Guid . Parse ( "08dc4c9d-147d-4117-83fa-5211ca38f639" ) , Guid . Parse ( "08dc4c9b-277f-4b4e-8a60-08581ec7a2cc" ) , Guid . Parse ( "08dc4c9b-1148-4b92-8589-a94f4870102e" ) , Guid . Parse ( "08dc4c9a-f6d7-4ca3-80b0-0609375e1c76" ) , Guid . Parse ( "08dc4c9a-c587-4754-87ad-430a0e10b072" ) , Guid . Parse ( "08dc4c9a-9d74-4436-8709-33bd7aa5d5f7" ) , Guid . Parse ( "08dc4c9a-65c9-4306-80bf-f279e011f2a8" ) , Guid . Parse ( "08dc4c9a-2588-4766-8f6e-5051eb3423f5" ) , Guid . Parse ( "08dc4c99-d3f1-4640-8307-ddaaa6c3a541" ) , Guid . Parse ( "08dc4c99-bc91-41e9-87fd-9c29def6618d" ) , Guid . Parse ( "08dc4c99-9c44-4e4a-876c-59688334acd5" ) , Guid . Parse ( "08dc4c99-8170-4a65-8e20-c08845d3ea86" ) , Guid . Parse ( "08dc4c99-31b4-4027-8509-b322a173d7d3" ) , Guid . Parse ( "08dc4c99-12ca-46d7-813c-c35acc6ec7ae" ) , Guid . Parse ( "08dc4c98-f71d-472e-89a7-c9a6cb731650" ) , Guid . Parse ( "08dc4c98-dc64-4a8f-846d-342f05a49d02" ) , Guid . Parse ( "08dc4c98-c01c-47cf-83c9-7974df162e55" ) , Guid . Parse ( "08dc4c98-a219-4402-8624-00a9ad3a65cb" ) , Guid . Parse ( "08dc4c98-8739-401f-8180-65a982ee4237" ) , Guid . Parse ( "08dc4966-b6ac-4b49-85d4-2e5319d9b009" ) , Guid . Parse ( "08dc432c-2bc5-4b81-8089-9c057c51192c" ) , Guid . Parse ( "08dc4307-0adc-4bcd-8213-5479bb010236" ) , Guid . Parse ( "08dc4271-7bf5-4600-839c-6c93a35d33a6" ) , Guid . Parse ( "08dc4261-8aa8-4a85-8991-fb2ac9bcb132" ) , Guid . Parse ( "08dc3f36-8af2-4fd4-83bf-6f25126eec13" ) , Guid . Parse ( "08dc3f1a-ed56-469f-8b1e-c4fe6b30442a" ) , Guid . Parse ( "08dc3e6c-4b50-4b2e-8584-a3a0462c1b29" ) , Guid . Parse ( "08dc3e51-df19-47d9-8dd4-063fe6011eb3" ) , Guid . Parse ( "08dc3db9-257d-470d-8256-3dc24f6fa332" ) , Guid . Parse ( "08dc7bcd-7248-42ba-8f0e-d50b2f7faed7" ) } ;
2024-06-20 18:08:28 +07:00
var profiles = await _dbContext . Set < Profile > ( )
. Include ( x = > x . Prefix )
. Include ( x = > x . Gender )
2024-06-24 20:53:47 +07:00
// .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)
2024-06-28 17:38:58 +07:00
. Where ( x = > orgIdSend . Contains ( x . Id ) )
2024-06-20 18:08:28 +07:00
. ToListAsync ( ) ;
2024-06-24 20:53:47 +07:00
var _baseAPI = _configuration [ "API" ] ;
// var _baseAPI = "http://localhost:13001/api/v1";
2024-06-19 14:50:38 +07:00
// create new profile
2024-06-20 18:08:28 +07:00
foreach ( var profile in profiles )
2024-06-19 14:50:38 +07:00
{
2024-06-28 17:38:58 +07:00
var apiUrl = $"{_baseAPI}/org/profile/all/dump-db" ;
2024-06-24 20:53:47 +07:00
// 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,
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// });
// var _result = await _res.Content.ReadAsStringAsync();
// //ยังไม่ SAVE จริง
// //profileId = JsonConvert.DeserializeObject<PlacementProfileId>(_result).result; /*แบบเก่า*/
// //profileId = JsonConvert.DeserializeAnonymousType(_result, new { result = "" }).result; /*แบบใหม่*/
// }
2024-06-20 18:08:28 +07:00
2024-06-21 14:58:00 +07:00
#region profileData
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-21 14:58:00 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-28 17:38:58 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-19 14:50:38 +07:00
2024-07-01 16:11:19 +07:00
var Insignias = await _dbContext . Set < ProfileInsignia > ( )
. Include ( x = > x . Insignia )
2024-07-02 22:22:55 +07:00
. Where ( x = > profile . Id = = x . ProfileId )
2024-07-01 16:11:19 +07:00
. 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 ( ) ;
}
}
}
2024-06-20 18:08:28 +07:00
2024-06-28 17:38:58 +07:00
// var Honor = await _dbContext.Set<ProfileHonor>()
// .Where(x => orgIdSend.Contains(x.ProfileId))
// .ToListAsync();
// if (Honor.Count > 0)
2024-06-24 20:53:47 +07:00
// {
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-20 18:08:28 +07:00
2024-06-24 20:53:47 +07:00
// 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();
// }
// }
// }
2024-06-21 14:58:00 +07:00
2024-06-20 18:08:28 +07:00
//profile.PlacementStatus = "CONTAIN";
//await _dbContext.SaveChangesAsync();
2024-06-21 14:58:00 +07:00
#endregion
2024-06-19 14:50:38 +07:00
}
2024-06-20 18:08:28 +07:00
//return "";
2024-06-19 14:50:38 +07:00
}
catch
{
throw ;
}
}
2023-07-28 15:04:26 +07:00
}
2024-06-19 14:50:38 +07:00
2023-07-28 15:04:26 +07:00
}