diff --git a/BMA.EHR.Application/ApplicationServicesRegistration.cs b/BMA.EHR.Application/ApplicationServicesRegistration.cs index e92d8c5d..0db5e99a 100644 --- a/BMA.EHR.Application/ApplicationServicesRegistration.cs +++ b/BMA.EHR.Application/ApplicationServicesRegistration.cs @@ -1,4 +1,5 @@ -using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Messaging; +using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Application.Repositories.Reports; @@ -28,6 +29,8 @@ namespace BMA.EHR.Application services.AddTransient(); services.AddTransient(); + services.AddTransient(); + return services; } } diff --git a/BMA.EHR.Infrastructure/Messaging/EmailSenderService.cs b/BMA.EHR.Application/Messaging/EmailSenderService.cs similarity index 97% rename from BMA.EHR.Infrastructure/Messaging/EmailSenderService.cs rename to BMA.EHR.Application/Messaging/EmailSenderService.cs index 08a52405..02a9195a 100644 --- a/BMA.EHR.Infrastructure/Messaging/EmailSenderService.cs +++ b/BMA.EHR.Application/Messaging/EmailSenderService.cs @@ -3,7 +3,7 @@ using Microsoft.Extensions.Configuration; using System.Net; using System.Net.Mail; -namespace BMA.EHR.Infrastructure.Messaging +namespace BMA.EHR.Application.Messaging { public class EmailSenderService { diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 8b1f1375..d0890b6c 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1,4 +1,6 @@ -using BMA.EHR.Application.Common.Interfaces; +using Amazon; +using BMA.EHR.Application.Common.Interfaces; +using BMA.EHR.Application.Messaging; using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Responses; using BMA.EHR.Domain.Extensions; @@ -30,6 +32,7 @@ namespace BMA.EHR.Application.Repositories.Commands private readonly OrganizationCommonRepository _organizationCommonRepository; private readonly UserProfileRepository _userProfileRepository; private readonly IConfiguration _configuration; + private readonly EmailSenderService _emailSenderService; #endregion @@ -39,13 +42,15 @@ namespace BMA.EHR.Application.Repositories.Commands IHttpContextAccessor httpContextAccessor, OrganizationCommonRepository organizationCommonRepository, UserProfileRepository userProfileRepository, - IConfiguration configuration) : base(dbContext, httpContextAccessor) + IConfiguration configuration, + EmailSenderService emailSenderService) : base(dbContext, httpContextAccessor) { _dbContext = dbContext; _httpContextAccessor = httpContextAccessor; _organizationCommonRepository = organizationCommonRepository; _userProfileRepository = userProfileRepository; _configuration = configuration; + _emailSenderService = emailSenderService; } #endregion @@ -1453,6 +1458,24 @@ namespace BMA.EHR.Application.Repositories.Commands case "C-PM-02": await ExecuteCommand01_02Async(command); break; + case "C-PM-11": + await ExecuteCommand11Async(command); + break; + case "C-PM-12": + await ExecuteCommand12Async(command); + break; + case "C-PM-17": + await ExecuteCommand17Async(command); + break; + case "C-PM-18": + await ExecuteCommand18Async(command); + break; + case "C-PM-19": + await ExecuteCommand19Async(command); + break; + case "C-PM-20": + await ExecuteCommand20Async(command); + break; default: throw new Exception(GlobalMessages.MethodForCommandTypeNotImplement); } @@ -1758,11 +1781,17 @@ namespace BMA.EHR.Application.Repositories.Commands await _dbContext.SaveChangesAsync(); - // Send noti inbox and email + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, Payload = "", }; @@ -1770,13 +1799,173 @@ namespace BMA.EHR.Application.Repositories.Commands var noti = new Notification { - Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ ตามคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", ReceiverUserId = profile.Id, Type = "", Payload = "", }; _dbContext.Set().Add(noti); await _dbContext.SaveChangesAsync(); + + + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-11 - คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand11Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.IsProbation = false; + + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Salaries.Add(salary); + + // update placementstatus + //data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); } // send cc noti inbox @@ -1785,18 +1974,844 @@ namespace BMA.EHR.Application.Repositories.Commands var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); if (pf != null) { - var inbox = new Inbox + if (cc.IsSendInbox) { - Subject = $"คุณได้รับสำเนาคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - Body = $"คำสั่งบบรรจุเป็นข้าราชการกรุงเทพมหานครสามัญ คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", - ReceiverUserId = pf.Id, - Payload = "", - }; - _dbContext.Set().Add(inbox); + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป คำสั่งเลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-12 - คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand12Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.IsActive = false; + data.IsLeave = true; + data.LeaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; + data.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Salaries.Add(salary); + + // update placementstatus + //data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-17 - คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand17Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.IsActive = false; + data.Profile.IsLeave = true; + data.Profile.LeaveReason = "ออกจากราชการ"; + data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Profile.Salaries.Add(salary); + + // update placementstatus + data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-18 - คำสั่งให้ออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand18Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.IsActive = false; + data.Profile.IsLeave = true; + data.Profile.LeaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการ"; + data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งให้ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Profile.Salaries.Add(salary); + + // update placementstatus + data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งให้ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-19 - คำสั่งให้ออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand19Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.IsActive = false; + data.Profile.IsLeave = true; + data.Profile.LeaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; + data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งปลดออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Profile.Salaries.Add(salary); + + // update placementstatus + data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งปลดออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + } + } + + // change command status + var cmdStatus = await _dbContext.Set().FirstOrDefaultAsync(x => x.Sequence == 5); + command.CommandStatusId = cmdStatus!.Id; + + await _dbContext.SaveChangesAsync(); + } + catch + { + throw; + } + } + + /// + /// C-PM-20 - คำสั่งให้ออกจากราชการ + /// + /// object ของรายการคำสั่ง + /// + private async Task ExecuteCommand20Async(Command command) + { + try + { + foreach (var recv in command.Receivers) + { + var data = await _dbContext.Set() + .Include(x => x.Profile) + .ThenInclude(x => x.Salaries) + .ThenInclude(x => x.PositionLevel) + + .FirstOrDefaultAsync(x => x.Id == recv.RefPlacementProfileId); + + if (data == null) + throw new Exception(GlobalMessages.DataNotFound); + + data.Profile.IsActive = false; + data.Profile.IsLeave = true; + data.Profile.LeaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; + data.Profile.LeaveDate = command.CommandAffectDate; + + var lastSarary = data.Profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); + var order = 1; + if (lastSarary.Order != null) + order = lastSarary.Order.Value + 1; + + var salary = new ProfileSalary + { + Order = order, + Date = command.CommandAffectDate, + Amount = lastSarary.Amount, + PositionSalaryAmount = lastSarary.PositionSalaryAmount, + MouthSalaryAmount = lastSarary.MouthSalaryAmount, + SalaryClass = "", + SalaryRef = "คำสั่งไล่ออกจากราชการ คำสั่ง" + command.IssuerOrganizationName + "ที่ " + $"{command.CommandNo}/{command.CommandYear} ลงวันที่ {command.CommandExcecuteDate!.Value.ToThaiFullDate3()}", + + OcId = lastSarary.OcId, + + + PositionLevel = lastSarary.PositionLevel, + PositionLineId = lastSarary.PositionLineId, + PositionTypeId = lastSarary.PositionTypeId, + OrganizationShortNameId = lastSarary.OrganizationShortNameId, + PosNoId = lastSarary.PosNoId, + + CommandNo = $"{command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()}", + CommandTypeName = command.CommandType.Name, + + + PositionEmployeeGroupId = null, + PositionEmployeeLevelId = null, + PositionEmployeePositionId = null, + PositionEmployeePositionSideId = null, + PosNoEmployee = "", + + + //PositionPathSideId = lastSarary.PositionPathSideId == null, + PositionExecutiveId = lastSarary.PositionExecutiveId, + //PositionExecutiveSideId = lastSarary.PositionExecutiveSideId, + + IsActive = true, + CreatedAt = DateTime.Now, + CreatedFullName = FullName ?? "System Administrator", + CreatedUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + + }; + + if (lastSarary.PositionPathSideId != null) salary.PositionPathSideId = lastSarary.PositionPathSideId; + if (lastSarary.PositionExecutiveSideId != null) salary.PositionExecutiveSideId = lastSarary.PositionExecutiveSideId; + + data.Profile.Salaries.Add(salary); + + // update placementstatus + data.Status = "DONE"; + + await _dbContext.SaveChangesAsync(); + + // TODO: ต้องเปลี่ยนเป็น Email จริงนะ ตอนนี้ Hardcode อยู่ + // Send noti inbox and email + var subject = $"คุณได้รับคำสั่งเลขที่ {command.CommandNo}/{command.CommandYear} ลงวันที่ {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} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Payload = "", + }; + _dbContext.Set().Add(inbox); + + var noti = new Notification + { + Body = $"คุณได้รับคำสั่งไล่ออกจากราชการ เลขที่ {command.CommandNo}/{command.CommandYear.ToInteger().ToThaiYear()} ลงวันที่ {command.CommandExcecuteDate.Value.ToThaiFullDate3()}", + ReceiverUserId = data.Profile.Id, + Type = "", + Payload = "", + }; + _dbContext.Set().Add(noti); + await _dbContext.SaveChangesAsync(); + } + + // send cc noti inbox + foreach (var cc in command.Deployments) + { + var pf = await _dbContext.Set().FirstOrDefaultAsync(x => x.CitizenId == cc.CitizenId); + if (pf != null) + { + 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 = pf.Id, + Payload = "", + }; + _dbContext.Set().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 = pf.Id, Type = "", Payload = "", diff --git a/BMA.EHR.Command.Service/Controllers/OrderController.cs b/BMA.EHR.Command.Service/Controllers/OrderController.cs index 3364cde7..90e005f8 100644 --- a/BMA.EHR.Command.Service/Controllers/OrderController.cs +++ b/BMA.EHR.Command.Service/Controllers/OrderController.cs @@ -1,4 +1,5 @@ -using BMA.EHR.Application.Repositories; +using BMA.EHR.Application.Messaging; +using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Requests.Commands; using BMA.EHR.Application.Responses; @@ -12,7 +13,6 @@ using BMA.EHR.Infrastructure.Persistence; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; -using System.Net; using System.Net.Http.Headers; using System.Security.Claims; @@ -37,6 +37,7 @@ namespace BMA.EHR.Command.Service.Controllers private readonly CommandTypeRepository _commandTypeRepository; private readonly CommandStatusRepository _commandStatusRepository; private readonly UserProfileRepository _userProfileRepository; + private readonly EmailSenderService _emailSenderService; #endregion @@ -50,7 +51,8 @@ namespace BMA.EHR.Command.Service.Controllers PrefixRepository prefixRepository, CommandTypeRepository commandTypeRepository, CommandStatusRepository commandStatusRepository, - UserProfileRepository userProfileRepository) + UserProfileRepository userProfileRepository, + EmailSenderService emailSenderService) { _repository = repository; _context = context; @@ -61,6 +63,7 @@ namespace BMA.EHR.Command.Service.Controllers _commandTypeRepository = commandTypeRepository; _commandStatusRepository = commandStatusRepository; _userProfileRepository = userProfileRepository; + _emailSenderService = emailSenderService; } #endregion @@ -88,6 +91,22 @@ namespace BMA.EHR.Command.Service.Controllers #region " Methods " + //[HttpGet("mail")] + //[AllowAnonymous] + //public IActionResult TestSendMail() + //{ + // try + // { + // _emailSenderService.SendMail("test send mail", "test body", "suphonchai@frappet.com"); + + // return Ok(); + // } + // catch + // { + // throw; + // } + //} + /// /// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ /// diff --git a/BMA.EHR.Command.Service/appsettings.json b/BMA.EHR.Command.Service/appsettings.json index 0b449f48..468cc133 100644 --- a/BMA.EHR.Command.Service/appsettings.json +++ b/BMA.EHR.Command.Service/appsettings.json @@ -34,5 +34,12 @@ "Protocol": "HTTPS", "Node": { "API": "https://bma-ehr.frappet.synology.me/api/v1/probation" + }, + "Mail": { + "Server": "smtp.gmail.com", + "User": "suphonchai.ph@gmail.com", + "Password": "nnjazjcnwhepkxdm", + "MailFrom": "suphonchai.ph@gmail.com", + "Port": "587" } } \ No newline at end of file diff --git a/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs b/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs index 955765ae..2773b8de 100644 --- a/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs +++ b/BMA.EHR.Infrastructure/InfrastructureServiceRegistration.cs @@ -1,6 +1,5 @@ using BMA.EHR.Application.Common.Interfaces; using BMA.EHR.Application.Repositories; -using BMA.EHR.Infrastructure.Messaging; using BMA.EHR.Infrastructure.Persistence; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; @@ -14,7 +13,7 @@ namespace BMA.EHR.Infrastructure IConfiguration configuration) { services.AddTransient(); - services.AddTransient(); + var connectionString = configuration.GetConnectionString("DefaultConnection");