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; using BMA.EHR.Command.Service.Requests; using BMA.EHR.Command.Service.Responses; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Commands.Core; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Swashbuckle.AspNetCore.Annotations; using System.Net.Http.Headers; using System.Security.Claims; namespace BMA.EHR.Command.Service.Controllers { [Route("api/v{version:apiVersion}/order")] [ApiVersion("1.0")] [ApiController] [Produces("application/json")] [Authorize] [SwaggerTag("API ระบบออกคำสั่ง")] public class OrderController : BaseController { #region " Fields " private readonly CommandRepository _repository; private readonly PlacementRepository _placementRepository; private readonly ApplicationDBContext _context; private readonly MinIOService _documentService; private readonly IHttpContextAccessor _httpContextAccessor; private readonly PrefixRepository _prefixRepository; private readonly CommandTypeRepository _commandTypeRepository; private readonly CommandStatusRepository _commandStatusRepository; private readonly UserProfileRepository _userProfileRepository; private readonly EmailSenderService _emailSenderService; #endregion #region " Constuctor and Destructor " public OrderController(CommandRepository repository, PlacementRepository placementRepository, ApplicationDBContext context, MinIOService documentService, IHttpContextAccessor httpContextAccessor, PrefixRepository prefixRepository, CommandTypeRepository commandTypeRepository, CommandStatusRepository commandStatusRepository, UserProfileRepository userProfileRepository, EmailSenderService emailSenderService) { _repository = repository; _context = context; _documentService = documentService; _httpContextAccessor = httpContextAccessor; _placementRepository = placementRepository; _prefixRepository = prefixRepository; _commandTypeRepository = commandTypeRepository; _commandStatusRepository = commandStatusRepository; _userProfileRepository = userProfileRepository; _emailSenderService = emailSenderService; } #endregion #region " Properties " private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); private Guid OcId { get { if (UserId != null || UserId != "") return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); else return Guid.Empty; } } #endregion #region " Methods " //[HttpGet("mail")] //[AllowAnonymous] //public IActionResult TestSendMail() //{ // try // { // _emailSenderService.SendMail("test send mail", "test body", "suphonchai@frappet.com"); // return Ok(); // } // catch // { // throw; // } //} /// /// แสดงปีเป็นปีพุทธศักราช โดยดึงจากข้อมูลที่มีในระบบ /// /// /// ถ้าไม่มีข้อมูลเลยจะ default ปีปัจจุบันให้ 1 รายการ /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("fiscal-year")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetFiscalAsync() { var data = await _repository.GetAllAsync(); if (data != null) { var _data = data.GroupBy(x => x.CommandYear).Select(x => new { Id = x.FirstOrDefault().CommandYear.ToInteger().ToCeYear(), Name = x.FirstOrDefault().CommandYear.ToInteger().ToThaiYear(), }).ToList(); if (_data == null || _data.Count == 0) { _data!.Add(new { Id = DateTime.Now.Year, Name = DateTime.Now.Year.ToThaiYear() }); } return Success(_data); } return Success(data); } /// /// แสดงประเภทคำสั่ง โดยดึงจากข้อมูลที่มีในระบบ /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("order-type")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandTypeAsync() { try { var data = (await _commandTypeRepository.GetAllAsync()).OrderBy(x => x.CommandCode); return Success(data); } catch { throw; } } /// /// ตรวจสอบความพร้อมในการออกคำสั่ง /// /// Record Id ของคำสั่ง /// /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("ready/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> CheckReadyToExcecuteAsync(Guid orderId) { try { var command = await _repository.GetByIdAsync(orderId); if (command == null) throw new Exception(GlobalMessages.CommandNotFound); var cover = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_COVER); var attatchment = command.Documents.FirstOrDefault(x => x.Category == GlobalConstants.TYPE_ATTACHMENT); switch (command.CommandType.CommandCode.ToUpper()) { case "C-PM-10": case "C-PM-11": case "C-PM-12": case "C-PM-16": case "C-PM-18": case "C-PM-19": case "C-PM-20": case "C-PM-21": { if (command.CommandNo != "" && command.CommandYear != null && command.CommandExcecuteDate != null && cover != null) { return Success(new { result = "Y" }); } else return Success(new { result = "N" }); } default: { if (command.CommandNo != "" && command.CommandYear != null && command.CommandExcecuteDate != null && cover != null && attatchment != null) { return Success(new { result = "Y" }); } else return Success(new { result = "N" }); } } } catch { throw; } } /// /// เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป /// /// Record Id ของคำสั่ง /// /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("next/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GoToNextState(Guid orderId) { try { await _repository.GotoNextStateAsync(orderId); return Success(); } catch { throw; } } /// /// เปลี่ยน status ของคำสั่งไปขั้นตอนก่อนหน้า /// /// Record Id ของคำสั่ง /// /// ค่า Y = พร้อมออกคำสั่ง, N = ยังไม่พร้อม /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("prev/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GoToPrevState(Guid orderId) { try { await _repository.GotoPrevStateAsync(orderId); return Success(); } catch { throw; } } /// /// PM7-19 : หน้าจอรายการออกคำสั่ง /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetAllAsync() { try { var data = (await _repository.GetAllAsync()) .Select(d => new { OrderId = d.Id, OrderName = d.CommandSubject, OrderNo = d.CommandNo, FiscalYear = d.CommandYear, OrderDate = d.CommandAffectDate, OrderByOrganization = d.IssuerOrganizationName, OrderBy = d.IssuerOrganizationName, OrderById = d.IssuerOrganizationId, signatoryBy = d.AuthorizedUserFullName, signatoryPosition = d.AuthorizedPosition, OrderStatusValue = d.CommandStatusId, OrderStatusName = d.CommandStatus.Name, OrderTypeValue = d.CommandTypeId, OrderTypeName = d.CommandType.Name }).ToList(); return Success(data); } catch { throw; } } /// /// PM7-20 : ลบรายการคำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpDelete("{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> DeleteAsync(Guid orderId) { try { var data = await _repository.GetByIdAsync(orderId); if (data == null) throw new Exception(GlobalMessages.DataNotFound); await _repository.DeleteAsync(data!); return Success(data); } catch { throw; } } /// /// PM7-21 : รายละเอียดการออกคำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetByIdAsync(Guid orderId) { try { var data = await _repository.GetByIdAsync(orderId); if (data == null) throw new Exception(GlobalMessages.DataNotFound); var result = new { orderId = orderId, orderTypeValue = data.CommandTypeId, orderTypeCode = data.CommandType.CommandCode.ToLower(), orderTitle = data.CommandSubject, orderNo = data.CommandNo, orderYear = data.CommandYear, orderDate = data.CommandAffectDate, orderBy = data.IssuerOrganizationId, signatoryBy = data.AuthorizedUserFullName, signatoryPosition = data.AuthorizedPosition, examRound = data.Placement == null ? Guid.Empty : data.Placement.Id, registerPosition = "", conclusionRegisterNo = data.ConclusionRegisterNo, conclusionRegisterDate = data.ConclusionRegisterDate, conclusionResultNo = data.ConclusionResultNo, conclusionResultDate = data.ConclusionResultDate, conclusionMeetingNo = data.ConclusionMeetingNo, conclusionMeetingDate = data.ConclusionMeetingDate, conclusionReturnNo = data.ConclusionReturnNo, conclusionReturnDate = data.ConclusionReturnDate, sourceOrganizationName = data.SourceOrganizationName, militaryCommandNo = data.MilitaryCommandNo, militaryCommanDate = data.MilitaryCommanDate, placementCommandIssuer = data.PlacementCommandIssuer, placementCommandNo = data.PlacementCommandNo, placementCommandDate = data.PlacementCommandDate, placementPositionName = data.PlacementPositionName, placementOrganizationName = data.PlacementOrganizationName, probationStartDate = data.ProbationStartDate, probationEndDate = data.ProbationEndDate, chairManFullName = data.ChairManFullName, member1FullName = data.Member1FullName, member2FullName = data.Member2FullName, receiveOrganizationName = data.ReceiveOrganizationName, transferOrganizationName = data.TransferOrganizationName, conclusionReceiveNo = data.ConclusionReceiveNo, conclusionReceiveDate = data.ConclusionReceiveDate, govAidCommandNo = data.GovAidCommandNo, govAidCommandDate = data.GovAidCommandDate, fault = data.Fault, guiltyBasis = data.GuiltyBasis, conclusionFireNo = data.ConclusionFireNo, conclusionFireDate = data.ConclusionFireDate, conclusionFireResolution = data.ConclusionFireResolution, OrderStatusValue = data.CommandStatusId, OrderStatusName = data.CommandStatus.Name, }; return Success(result); } catch { throw; } } #region " Put and Post " #region " C-PM-01 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-01 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-01/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType01Async([FromBody] CreateCommandRequest req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, PositionName = req.registerPosition, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, // c-pm-01 ถึง c-pm-04 PlacementId = req.examRound, ConclusionRegisterNo = req.conclusionRegisterNo ?? "", ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionResultNo = req.conclusionResultNo, ConclusionResultDate = req.conclusionResultDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-01 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-01/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType01Async(Guid orderId, [FromBody] CreateCommandRequest req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.PositionName = req.registerPosition; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; // c-pm-01 ถึง c-pm-04 var placement = await _placementRepository.GetByIdAsync(req.examRound); order.Placement = placement!; order.ConclusionRegisterNo = req.conclusionRegisterNo; order.ConclusionRegisterDate = req.conclusionRegisterDate; order.ConclusionResultNo = req.conclusionResultNo; order.ConclusionResultDate = req.conclusionResultDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-02 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-02 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-02/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType02Async([FromBody] CreateCommandRequest req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, PositionName = req.registerPosition, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, // c-pm-01 ถึง c-pm-04 PlacementId = req.examRound, ConclusionRegisterNo = req.conclusionRegisterNo ?? "", ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionResultNo = req.conclusionResultNo, ConclusionResultDate = req.conclusionResultDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-02 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-02/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType02Async(Guid orderId, [FromBody] CreateCommandRequest req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.PositionName = req.registerPosition; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; // c-pm-01 ถึง c-pm-04 var placement = await _placementRepository.GetByIdAsync(req.examRound); order.Placement = placement!; order.ConclusionRegisterNo = req.conclusionRegisterNo; order.ConclusionRegisterDate = req.conclusionRegisterDate; order.ConclusionResultNo = req.conclusionResultNo; order.ConclusionResultDate = req.conclusionResultDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-03 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-03 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-03/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType03Async([FromBody] CreateCommandRequest req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, PositionName = req.registerPosition, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, // c-pm-01 ถึง c-pm-04 PlacementId = req.examRound, ConclusionRegisterNo = req.conclusionRegisterNo ?? "", ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionResultNo = req.conclusionResultNo, ConclusionResultDate = req.conclusionResultDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-04 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-03/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType03Async(Guid orderId, [FromBody] CreateCommandRequest req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.PositionName = req.registerPosition; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; // c-pm-01 ถึง c-pm-04 var placement = await _placementRepository.GetByIdAsync(req.examRound); order.Placement = placement!; order.ConclusionRegisterNo = req.conclusionRegisterNo; order.ConclusionRegisterDate = req.conclusionRegisterDate; order.ConclusionResultNo = req.conclusionResultNo; order.ConclusionResultDate = req.conclusionResultDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-04 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-04 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-04/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType04Async([FromBody] CreateCommandRequest req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, PositionName = req.registerPosition, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, // c-pm-01 ถึง c-pm-04 PlacementId = req.examRound, ConclusionRegisterNo = req.conclusionRegisterNo ?? "", ConclusionRegisterDate = req.conclusionRegisterDate, ConclusionResultNo = req.conclusionResultNo, ConclusionResultDate = req.conclusionResultDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-04 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-04/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType04Async(Guid orderId, [FromBody] CreateCommandRequest req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.PositionName = req.registerPosition; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; // c-pm-01 ถึง c-pm-04 var placement = await _placementRepository.GetByIdAsync(req.examRound); order.Placement = placement!; order.ConclusionRegisterNo = req.conclusionRegisterNo; order.ConclusionRegisterDate = req.conclusionRegisterDate; order.ConclusionResultNo = req.conclusionResultNo; order.ConclusionResultDate = req.conclusionResultDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-05 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-05 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-05/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType05Async([FromBody] CreateCommandGroup2Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, ConclusionMeetingNo = req.conclusionMeetingNo, ConclusionMeetingDate = req.conclusionMeetingDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-05 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-05/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType05Async(Guid orderId, [FromBody] CreateCommandGroup2Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.ConclusionMeetingNo = req.conclusionMeetingNo; order.ConclusionMeetingDate = req.conclusionMeetingDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-06 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-06 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-06/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType06Async([FromBody] CreateCommandGroup2Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, ConclusionMeetingNo = req.conclusionMeetingNo, ConclusionMeetingDate = req.conclusionMeetingDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-06 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-06/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType06Async(Guid orderId, [FromBody] CreateCommandGroup2Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.ConclusionMeetingNo = req.conclusionMeetingNo; order.ConclusionMeetingDate = req.conclusionMeetingDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-07 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-07 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-07/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType07Async([FromBody] CreateCommandGroup3Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-07 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-07/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType07Async(Guid orderId, [FromBody] CreateCommandGroup3Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-08 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-08 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-08/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType08Async([FromBody] CreateCommandGroup4Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, ConclusionReturnNo = req.conclusionReturnNo, ConclusionReturnDate = req.conclusionReturnDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-08 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-08/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType08Async(Guid orderId, [FromBody] CreateCommandGroup4Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.ConclusionReturnNo = req.conclusionReturnNo; order.ConclusionReturnDate = req.conclusionReturnDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-09 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-09 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-09/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType09Async([FromBody] CreateCommandGroup5Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, ConclusionReturnNo = req.conclusionReturnNo, ConclusionReturnDate = req.conclusionReturnDate, SourceOrganizationName = req.sourceOrganizationName, MilitaryCommandNo = req.militaryCommandNo, MilitaryCommanDate = req.militaryCommandDate }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-09 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-09/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType09Async(Guid orderId, [FromBody] CreateCommandGroup5Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.ConclusionReturnNo = req.conclusionReturnNo; order.ConclusionReturnDate = req.conclusionReturnDate; order.SourceOrganizationName = req.sourceOrganizationName; order.MilitaryCommandNo = req.militaryCommandNo; order.MilitaryCommanDate = req.militaryCommandDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-10 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-10 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-10/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType10Async([FromBody] CreateCommandGroup6Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, PlacementCommandIssuer = req.placementCommandIssuer, PlacementCommandNo = req.placementCommandNo, PlacementCommandDate = req.placementCommandDate, PlacementPositionName = req.placementPositionName, PlacementOrganizationName = req.placementOrganizationName, ProbationStartDate = req.probationStartDate, ProbationEndDate = req.probationEndDate, ChairManFullName = req.chairManFullName, Member1FullName = req.member1FullName, Member2FullName = req.member2FullName, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-10 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-10/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType10Async(Guid orderId, [FromBody] CreateCommandGroup6Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.PlacementCommandIssuer = req.placementCommandIssuer; order.PlacementCommandNo = req.placementCommandNo; order.PlacementCommandDate = req.placementCommandDate; order.PlacementPositionName = req.placementPositionName; order.PlacementOrganizationName = req.placementOrganizationName; order.ProbationStartDate = req.probationStartDate; order.ProbationEndDate = req.probationEndDate; order.ChairManFullName = req.chairManFullName; order.Member1FullName = req.member1FullName; order.Member2FullName = req.member2FullName; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-11 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-11 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-11/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType11Async([FromBody] CreateCommandGroup7Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, PlacementCommandIssuer = req.placementCommandIssuer, PlacementCommandNo = req.placementCommandNo, PlacementCommandDate = req.placementCommandDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-11 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-11/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType11Async(Guid orderId, [FromBody] CreateCommandGroup7Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.PlacementCommandIssuer = req.placementCommandIssuer; order.PlacementCommandNo = req.placementCommandNo; order.PlacementCommandDate = req.placementCommandDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-12 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-12 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-12/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType12Async([FromBody] CreateCommandGroup7Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, PlacementCommandIssuer = req.placementCommandIssuer, PlacementCommandNo = req.placementCommandNo, PlacementCommandDate = req.placementCommandDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-12 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-12/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType12Async(Guid orderId, [FromBody] CreateCommandGroup7Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.PlacementCommandIssuer = req.placementCommandIssuer; order.PlacementCommandNo = req.placementCommandNo; order.PlacementCommandDate = req.placementCommandDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-13 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-13 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-13/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType13Async([FromBody] CreateCommandGroup8Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, ReceiveOrganizationName = req.receiveOrganizationName, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-13 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-13/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType13Async(Guid orderId, [FromBody] CreateCommandGroup8Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.ReceiveOrganizationName = req.receiveOrganizationName; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-14 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-14 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-14/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType14Async([FromBody] CreateCommandGroup9Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, TransferOrganizationName = req.transferOrganizationName, ConclusionReceiveNo = req.conclusionReceiveNo, ConclusionReceiveDate = req.conclusionReceiveDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-14 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-14/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType14Async(Guid orderId, [FromBody] CreateCommandGroup9Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.TransferOrganizationName = req.transferOrganizationName; order.ConclusionReceiveNo = req.conclusionReceiveNo; order.ConclusionReceiveDate = req.conclusionReceiveDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-15 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-15 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-15/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType15Async([FromBody] CreateCommandGroup0Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-15 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-15/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType15Async(Guid orderId, [FromBody] CreateCommandGroup0Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-16 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-16 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-16/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType16Async([FromBody] CreateCommandGroup10Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, GovAidCommandNo = req.govAidCommandNo, GovAidCommandDate = req.govAidCommandDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-16 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-16/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType16Async(Guid orderId, [FromBody] CreateCommandGroup10Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.GovAidCommandNo = req.govAidCommandNo; order.GovAidCommandDate = req.govAidCommandDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-17 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-17 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-17/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType17Async([FromBody] CreateCommandGroup0Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-17 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-17/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType17Async(Guid orderId, [FromBody] CreateCommandGroup0Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-18 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-18 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-18/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType18Async([FromBody] CreateCommandGroup11Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, Fault = req.fault, GuiltyBasis = req.guiltyBasis, ConclusionFireNo = req.conclusionFireNo, ConclusionFireDate = req.conclusionFireDate, ConclusionFireResolution = req.conclusionFireResolution, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-18 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-18/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType18Async(Guid orderId, [FromBody] CreateCommandGroup11Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.Fault = req.fault; order.GuiltyBasis = req.guiltyBasis; order.ConclusionFireNo = req.conclusionFireNo; order.ConclusionFireDate = req.conclusionFireDate; order.ConclusionFireResolution = req.conclusionFireResolution; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-19 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-19 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-19/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType19Async([FromBody] CreateCommandGroup11Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, Fault = req.fault, GuiltyBasis = req.guiltyBasis, ConclusionFireNo = req.conclusionFireNo, ConclusionFireDate = req.conclusionFireDate, ConclusionFireResolution = req.conclusionFireResolution, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-19 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-19/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType19Async(Guid orderId, [FromBody] CreateCommandGroup11Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.Fault = req.fault; order.GuiltyBasis = req.guiltyBasis; order.ConclusionFireNo = req.conclusionFireNo; order.ConclusionFireDate = req.conclusionFireDate; order.ConclusionFireResolution = req.conclusionFireResolution; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-20 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-20 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-20/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType20Async([FromBody] CreateCommandGroup11Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, Fault = req.fault, GuiltyBasis = req.guiltyBasis, ConclusionFireNo = req.conclusionFireNo, ConclusionFireDate = req.conclusionFireDate, ConclusionFireResolution = req.conclusionFireResolution, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-20 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-20/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType20Async(Guid orderId, [FromBody] CreateCommandGroup11Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; order.Fault = req.fault; order.GuiltyBasis = req.guiltyBasis; order.ConclusionFireNo = req.conclusionFireNo; order.ConclusionFireDate = req.conclusionFireDate; order.ConclusionFireResolution = req.conclusionFireResolution; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #region " C-PM-21 " /// /// PM7-22 : สร้างข้อมูลรายละเอียดการออกคำสั่ง C-PM-21 /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("c-pm-21/detail")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostType21Async([FromBody] CreateCommandGroup7Request req) { try { var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var inserted = new Domain.Models.Commands.Core.Command { CommandNo = req.orderNo, CommandYear = req.orderYear.ToString(), CommandSubject = req.orderTitle, CommandTypeId = req.orderTypeValue, IssuerOrganizationId = req.orderBy, IssuerOrganizationName = req.orderByOrganizationName, AuthorizedUserFullName = req.signatoryBy, AuthorizedPosition = req.signatoryPosition, CommandAffectDate = req.orderDate, OwnerGovId = OcId, PlacementCommandIssuer = req.placementCommandIssuer, PlacementCommandNo = req.placementCommandNo, PlacementCommandDate = req.placementCommandDate, }; var result = await _repository.AddAsync(inserted); return Success(result); } catch { throw; } } /// /// PM7-23 : แก้ไขข้อมูลรายละเอียดการออกคำสั่ง C-PM-21 /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("c-pm-21/detail/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PutType21Async(Guid orderId, [FromBody] CreateCommandGroup7Request req) { try { var order = await _repository.GetByIdAsync(orderId); if (order == null) throw new Exception(GlobalMessages.CommandNotFound); var commandType = await _commandTypeRepository.GetByIdAsync(req.orderTypeValue); var status = await _commandStatusRepository.GetByIdAsync(order.CommandStatusId); order.CommandNo = req.orderNo; order.CommandYear = req.orderYear.ToString(); order.CommandSubject = req.orderTitle; order.CommandType = commandType!; order.IssuerOrganizationId = req.orderBy; order.IssuerOrganizationName = req.orderByOrganizationName; order.AuthorizedUserFullName = req.signatoryBy; order.AuthorizedPosition = req.signatoryPosition; order.CommandStatus = status!; order.CommandAffectDate = req.orderDate; //order.PlacementCommandIssuer = req.placementCommandIssuer; //order.PlacementCommandNo = req.placementCommandNo; //order.PlacementCommandDate = req.placementCommandDate; var result = await _repository.UpdateAsync(order); return Success(result); } catch { throw; } } #endregion #endregion /// /// PM7-24 : dropdown รอบการสอบ หน้ารายละเอียดการออกคำสั่ง /// /// Code ของประเภทคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("detail/exam-round/{commandCode}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetExamRoundAsync(string commandCode) { try { var rawData = commandCode.Trim().ToUpper() == "C-PM-01" ? await _placementRepository.GetCompetitivePlacementAsync() : await _placementRepository.GetQualifyingPlacementAsync(); var data = rawData.Select(x => new { examRoundValue = x.Id, examRoundName = $"{x.Name} ครั้งที่ {x.Round}/{x.Year.ToThaiYear()}" }) .ToList(); return Success(data); } catch { throw; } } /// /// PM7-26 : ข้อมูลเลือกรายชื่อออกคำสั่ง ** ยังไม่ได้กรองหน่วยงาน ** ** แสดงรายการจากระบบบรรจุ ** /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("persons/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandReceiverAsync([FromHeader] string authorization, Guid orderId) { try { var token = string.Empty; if (AuthenticationHeaderValue.TryParse(authorization, out var headerValue)) { // we have a valid AuthenticationHeaderValue that has the following details: var scheme = headerValue.Scheme; token = headerValue.Parameter; // scheme will be "Bearer" // parmameter will be the token itself. } var command = await _repository.GetByIdAsync(orderId); if (command == null) throw new Exception(GlobalMessages.CommandNotFound); // TODO : หาค่า Education มาแสดง var existed = await _repository.GetReceiverByCommmandIdAsync(orderId); var receivers = (await _repository.GetReceiverForCommandAsync(orderId, token!)) .OrderBy(x => x.Sequence) .Select(r => new CommandReceiverResponse { RefRecordId = r.RefPlacementProfileId!.Value, PersonalId = r.Id, Sequence = r.Sequence, IdCard = r.CitizenId, Name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}", SelectStatus = existed.FirstOrDefault(x => x.RefPlacementProfileId!.Value == r.RefPlacementProfileId!.Value) != null, Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน }).ToList(); // ให้ Update Salary เฉพาะของ Command 01-04 switch (command.CommandType.CommandCode.ToUpper()) { case "C-PM-01": case "C-PM-02": case "C-PM-03": case "c-PM-04": { foreach (var r in receivers) { var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); r.SalaryAmount = salary.SalaryAmount; r.PositionSalaryAmount = salary.PositionSalaryAmount; r.MonthSalaryAmount = salary.MonthSalaryAmount; } } break; default: { foreach (var r in receivers) { var salary = await _repository.GetCommandReceiverSalary(r.PersonalId); r.SalaryAmount = salary.SalaryAmount; r.PositionSalaryAmount = salary.PositionSalaryAmount; r.MonthSalaryAmount = salary.MonthSalaryAmount; } } break; } return Success(receivers); } catch { throw; } } /// /// ข้อมูลเลือกรายชื่อออกคำสั่ง ** ที่ได้เลือกเอาไว้แล้ว ** /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("persons-selected/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandSelectReceiverAsync(Guid orderId) { try { var command = await _repository.GetByIdAsync(orderId); if (command == null) throw new Exception(GlobalMessages.CommandNotFound); var receivers = (await _repository.GetReceiverByCommmandIdAsync(orderId)) .OrderBy(x => x.Sequence) .Select(r => new CommandReceiverResponse { RefRecordId = r.RefPlacementProfileId!.Value, PersonalId = r.Id, Sequence = r.Sequence, IdCard = r.CitizenId, Name = $"{r.Prefix!}{r.FirstName!} {r.LastName!}", SelectStatus = true, Education = "" // ยังหาไม่เจอว่าอยุ่ field ไหน }).ToList(); // ให้ Update Salary เฉพาะของ Command 01-04 switch (command.CommandType.CommandCode.ToUpper()) { case "C-PM-01": case "C-PM-02": case "C-PM-03": case "C-PM-04": { foreach (var r in receivers) { var salary = await _repository.GetPlacementSalaryAsync(r.RefRecordId); r.SalaryAmount = salary.SalaryAmount; r.PositionSalaryAmount = salary.PositionSalaryAmount; r.MonthSalaryAmount = salary.MonthSalaryAmount; } break; } default: { foreach (var r in receivers) { var salary = await _repository.GetCommandReceiverSalary(r.PersonalId); r.SalaryAmount = salary.SalaryAmount; r.PositionSalaryAmount = salary.PositionSalaryAmount; r.MonthSalaryAmount = salary.MonthSalaryAmount; } } break; } return Success(receivers); } catch { throw; } } /// /// บันทึกข้อมูลเลือกรายชื่อออกคำสั่ง ** ที่ได้เลือกเอาไว้แล้ว ** /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("persons/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> SaveCommandSelectReceiverAsync([FromHeader] string authorization, Guid orderId, [FromBody] List selected) { try { var token = string.Empty; if (AuthenticationHeaderValue.TryParse(authorization, out var headerValue)) { // we have a valid AuthenticationHeaderValue that has the following details: var scheme = headerValue.Scheme; token = headerValue.Parameter; // scheme will be "Bearer" // parmameter will be the token itself. } await _repository.SaveSelectedReceiverAsync(orderId, selected, token); return Success(); } catch { throw; } } /// /// PM7-27 : ลบข้อมูลเลือกรายชื่อออกคำสั่ง /// /// /// ** ยังไม่ได้กรองหน่วยงาน ** /// /// Record Id ของผู้รับคำสั่งในรายการบัญชีแนบท้าย /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpDelete("persons/{personalId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> DeleteCommandReceiverAsync(Guid personalId) { try { var receiver = await _repository.DeleteCommandReceiverAsync(personalId); return Success(receiver); } catch { throw; } } /// /// PM7-28 : ข้อมูลเลือกรายชื่อส่งสำเนาคำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("copy-order/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandDeploymentAsync(Guid orderId) { try { var deployments = (await _repository.GetDeploymentByCommandIdAsync(orderId)) .Select(x => new { personalId = x.Id, sequence = x.Sequence, selectStatus = true, idCard = x.CitizenId, name = $"{x.Prefix}{x.FirstName} {x.LastName}", position = x.PositionName, unit = x.OrganizationName, emailChannel = x.IsSendMail, inboxChannel = x.IsSendInbox }) .ToList(); return Success(deployments); } catch { throw; } } /// /// PM7-30 : popup - เลือกรายชื่อส่งสำเนาคำสั่ง /// /// Record Id ของหน่วยงาน /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("copy-order/persons/{organizationId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetPeopleByOrganizationIdAsync(Guid organizationId) { try { var people = (await _repository.GetProfileByOrganizationIdAsync(organizationId)) .Select(x => new { profileId = x.Profile!.Id, idCard = x.Profile!.CitizenId, name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}", position = x.OrganizationPosition!.PositionMaster!.PositionPath!.Name, unit = x.OrganizationPosition!.Organization!.OrganizationOrganization!.Name, prefixId = x.Profile!.Prefix!.Id, firstName = x.Profile!.FirstName, lastName = x.Profile!.LastName }) .ToList(); return Success(people); } catch { throw; } } /// /// PM7-31 : เพิ่มรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("copy-order/persons/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> CreateCommandDeploymentAsync(Guid orderId, [FromBody] List req) { try { // transform req var deploys = new List(); foreach (var p in req) { var prefix = await _prefixRepository.GetByIdAsync(p.PrefixId); deploys.Add(new CommandDeployment { CitizenId = p.IdCard, Prefix = prefix.Name, FirstName = p.FirstName, LastName = p.LastName, OrganizationName = p.Unit, PositionName = p.Position }); } await _repository.CreateCommandDeploymentAsync(orderId, deploys); return Success(); } catch { throw; } } /// /// PM7-32 : บันทึกช่องทางการส่งสำเนาคำสั่ง /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("copy-order")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> UpdateCommandDeploymentAsync([FromBody] List req) { try { // transform var deploys = new List(); foreach (var p in req) { var updated = await _repository.GetCommandDeploymentById(p.PersonalId); updated!.IsSendInbox = p.InboxChannel; updated!.IsSendMail = p.EmailChannel; deploys.Add(updated); } await _repository.UpdatCommandDeploymentAsync(deploys); return Success(); } catch { throw; } } /// /// PM7-33 : ลบรายชื่อคนที่ต้องการส่งสำเนาคำสั่ง /// /// Record Id ของผู้รับสำเนาคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpDelete("copy-order/{personalId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> DeleteCommandDeloymentAsync(Guid personalId) { try { await _repository.DeleteCommandDeploymentAsync(personalId); return Success(); } catch { throw; } } #region " Documents " /// /// PM7-34 : ข้อมูลรายละเอียดคำสั่งและแนบท้าย /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("attachment/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandAttatchmentAsync(Guid orderId) { try { var command = await _repository.GetByIdAsync(orderId); if (command == null) throw new Exception(GlobalMessages.CommandNotFound); var documents = await _repository.GetCommandDocumentAsync(orderId); var cover = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_COVER).FirstOrDefault(); var attach = documents.Where(x => x.Category.Trim().ToLower() == GlobalConstants.TYPE_ATTACHMENT).FirstOrDefault(); var result = new { orderNo = command.CommandNo, orderYear = command.CommandYear, signDate = command.CommandExcecuteDate, orderFileUrl = cover == null ? null : await _documentService.ImagesPath(cover.Document.Id), attachmentFileUrl = attach == null ? null : await _documentService.ImagesPath(attach.Document.Id), }; return Success(result); } catch { throw; } } /// /// PM7-35 : อัปโหลดไฟล์คำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("attachment/order-file/{orderId}"), DisableRequestSizeLimit] [Consumes("multipart/form-data")] [SwaggerOperation( Summary = "Upload a file", Description = "Upload a file using multipart/form-data", OperationId = "UploadCommandCoverAsync" //Tags = new[] { "File" } )] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> UploadCommandCoverAsync(Guid orderId) { try { // check upload file if (Request.Form.Files == null || Request.Form.Files.Count == 0) { return Error(GlobalMessages.NoFileToUpload); } var file = Request.Form.Files[0]; // get exit file var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_COVER); // delete exist document from s3 foreach (var doc in docs) { await _documentService.DeleteFileAsync(doc.Document.Id); } // upload new document to s3 var cover = await _documentService.UploadFileAsync(file); // create new CommandDocumentEntity var commandDoc = new CommandDocument { Category = GlobalConstants.TYPE_COVER, Document = cover, }; // send to repo to save in database await _repository.UploadDocument(orderId, GlobalConstants.TYPE_COVER, commandDoc); return Success(); } catch { throw; } } /// /// PM7-36 : อัปโหลดไฟล์เอกสารแนบท้าย /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("attachment/file/{orderId}"), DisableRequestSizeLimit] [Consumes("multipart/form-data")] [SwaggerOperation( Summary = "Upload a file", Description = "Upload a file using multipart/form-data", OperationId = "UploadCommandAttachmentAsync" //Tags = new[] { "File" } )] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> UploadCommandAttachmentAsync(Guid orderId) { try { // check upload file if (Request.Form.Files == null || Request.Form.Files.Count == 0) { return Error(GlobalMessages.NoFileToUpload); } var file = Request.Form.Files[0]; // get exit file var docs = await _repository.GetExistDocument(orderId, GlobalConstants.TYPE_ATTACHMENT); // delete exist document from s3 foreach (var doc in docs) { await _documentService.DeleteFileAsync(doc.Document.Id); } // upload new document to s3 var cover = await _documentService.UploadFileAsync(file); // create new CommandDocumentEntity var commandDoc = new CommandDocument { Category = GlobalConstants.TYPE_ATTACHMENT, Document = cover, }; // send to repo to save in database await _repository.UploadDocument(orderId, GlobalConstants.TYPE_ATTACHMENT, commandDoc); return Success(); } catch { throw; } } #endregion /// /// PM7-37 : บันทึกข้อมูลคำสั่งและแนบท้าย /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("attachment/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> UpdateCommandExecuteAsync(Guid orderId, [FromBody] UpdateCommandExecuteRequest req) { try { await _repository.UpdateCommandInfoAsync(orderId, req.OrderNo, req.OrderYear, req.SignDate); return Success(); } catch { throw; } } /// /// อ่านข้อมูลเงินเดือนสำหรับผู้บรรจุ จากข้อมูลระบบสรรหา /// /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("salary/{personalId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetPlacementSalaryAsync(Guid personalId) { try { var record = await _repository.GetCommandReceiverAsync(personalId); if (record == null) { throw new Exception(GlobalMessages.DataNotFound); } var data = new PlacementSalaryResponse(); switch (record.Command.CommandType.CommandCode.ToUpper()) { case "C-PM-01": case "C-PM-02": case "C-PM-03": case "C-PM-04": data = await _repository.GetPlacementSalaryAsync(record!.RefPlacementProfileId!.Value); break; default: data = await _repository.GetCommandReceiverSalary(personalId); break; } return Success(data); } catch { throw; } } /// /// บันทึกข้อมูลเงินเดือนสำหรับผู้บรรจุ /// /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("salary/{personalId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> UpdatePlacementSalaryAsync(Guid personalId, [FromBody] UpdatePlacementSalaryRequest req) { try { var receiver = await _repository.GetCommandReceiverAsync(personalId); if (receiver == null) throw new Exception(GlobalMessages.DataNotFound); switch (receiver.Command.CommandType.CommandCode.ToUpper()) { case "C-PM-01": case "C-PM-02": case "C-PM-03": case "C-PM-04": await _repository.UpdatePlacementSalaryAsync(personalId, req); return Success(); default: await _repository.UpdateCommandReceiverSalaryAsync(personalId, req); return Success(); } } catch { throw; } } /// /// สลับลำดับข้อมูลในบัญชีแนบท้ายขึ้น /// /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("swap/up/{personalId}")] public async Task> SwapUpReceiverOrderAsync(Guid personalId) { try { await _repository.SwapReceiverOrderAsync(personalId, "up"); return Success(); } catch { throw; } } /// /// สลับลำดับข้อมูลในบัญชีแนบท้ายลง /// /// Record Id ของผู้รับคำสั่งในบัญชีแนบท้าย /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("swap/down/{personalId}")] public async Task> SwapDownReceiverOrderAsync(Guid personalId) { try { await _repository.SwapReceiverOrderAsync(personalId, "down"); return Success(); } catch { throw; } } /// /// ออกคำสั่ง /// /// Record Id ของคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("execute/{orderId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> ExecuteCommandAsync(Guid orderId) { try { await _repository.ExecuteCommandAsync(orderId); return Success(); } catch { throw; } } /// /// แสดงรายชื่อหน่วยงานสำหรับเลือกเพื่อออกคำสั่ง /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("organizations")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandOrganizationAsync() { try { var data = await _repository.GetCommandOrgAsync(); return Success(data); } catch { throw; } } /// /// แสดงชื่อผู้อนุมัติในรายการคำสั่ง /// /// Id ของหน่วยงานที่เลือกเพื่อออกคำสั่ง /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("approver/{ocId}")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandOrganizationApproverAsync(Guid ocId) { try { var data = await _repository.GetOrgApproverAsync(ocId); return Success(data); } catch { throw; } } /// /// แสดงชื่อผู้เกี่ยวข้องกับคำสั่ง /// /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("search/profile/command")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> GetCommandProfileAsync([FromBody] SearchProfileCommandRequest req) { try { var data = await _repository.GetCommandProfileAsync(req.CommandType, req.Year, req.Posno); return Success(data); } catch { throw; } } #endregion } }