using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.OrganizationEmployee;
using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared;
using DocumentFormat.OpenXml.Drawing.Charts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Annotations;
using Telerik.Reporting;
using Telerik.Reporting.Processing;

namespace BMA.EHR.Report.Service.Controllers
{
    [Route("api/v{version:apiVersion}/report/order")]
    [ApiVersion("2.0")]
    [ApiController]
    [Produces("application/json")]
    [Authorize]
    [SwaggerTag("API รายงานระบบออกคำสั่ง")]
    public class CommandReportController : BaseController
    {
        #region " Fields "

        private readonly CommandRepository _repository;
        private readonly IWebHostEnvironment _hostingEnvironment;
        private readonly IConfiguration _configuration;
        private readonly CommandReportRepository _commandReportRepository;
        private readonly GenericReportGenerator _reportGenerator;

        #endregion

        #region " Constuctor and Destructor "

        public CommandReportController(CommandRepository repository,
                                       IWebHostEnvironment hostingEnvironment,
                                       IConfiguration configuration,
                                       CommandReportRepository commandReportRepository,
                                       GenericReportGenerator reportGenerator)
        {
            _repository = repository;
            _hostingEnvironment = hostingEnvironment;
            _configuration = configuration;
            _commandReportRepository = commandReportRepository;
            _reportGenerator = reportGenerator;
        }

        #endregion

        #region " Methods "

        #region " Private "

        #region " C-PM-01 "

        private async Task<byte[]> GenerateCommandReportType01_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-1.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType01_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType01AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"01-คำสั่งบรรจุและแต่งตั้งผู้สอบแข่งขันได้-2.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-02 "

        private async Task<byte[]> GenerateCommandReportType02_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType02_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType02AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-4.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-03 "

        private async Task<byte[]> GenerateCommandReportType03_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน-Head.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType03_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType03AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"03-คำสั่งแต่งตั้งผู้สอบแข่งขัน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-04 "

        private async Task<byte[]> GenerateCommandReportType04_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"04-คำสั่งย้ายผู้สอบแข่งขัน-Head.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType04_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType03AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"04-คำสั่งย้ายผู้สอบแข่งขัน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-05 "

        private async Task<byte[]> GenerateCommandReportType05_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType05_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType05_06AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-06 "

        private async Task<byte[]> GenerateCommandReportType06_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-คำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType06_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType05_06AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"05-06-แนบท้ายคำสั่งแต่งตั้ง-คำสั่งเลื่อน.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-07 "

        private async Task<byte[]> GenerateCommandReportType07_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"07-คำสั่งย้าย.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType07_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType07AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"07-แนบท้ายคำสั่งย้าย.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["tblData"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-08 "

        private async Task<byte[]> GenerateCommandReportType08_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                    ConclusionReturnNo = raw_data.ConclusionReturnNo,
                    ConclusionReturnDate = raw_data.ConclusionReturnDate == null ? "" : raw_data.ConclusionReturnDate.Value.ToThaiFullDate3(),
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"08-คำสั่งบรรจุและแต่งตั้งข้าราชการฯกลับเข้ารับราชการ-5.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType08_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType08AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"08-คำสั่งบรรจุและแต่งตั้งข้าราชการฯกลับเข้ารับราชการ-6.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-09 "

        private async Task<byte[]> GenerateCommandReportType09_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                    ConclusionReturnNo = raw_data.ConclusionReturnNo,
                    ConclusionReturnDate = raw_data.ConclusionReturnDate == null ? "" : raw_data.ConclusionReturnDate.Value.ToThaiFullDate3(),
                    SourceOrganizationName = raw_data.SourceOrganizationName,
                    MilitaryCommandNo = raw_data.MilitaryCommandNo,
                    MilitaryCommanDate = raw_data.MilitaryCommanDate == null ? "" : raw_data.MilitaryCommanDate.Value.ToThaiFullDate3()
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"09-คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ-7.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType09_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType09AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"09-คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ-8.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-10 "

        private async Task<byte[]> GenerateCommandReportType10_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,

                    PlacementCommandIssuer = raw_data.PlacementCommandIssuer,
                    PlacementCommandNo = raw_data.PlacementCommandNo,
                    PlacementCommandDate = raw_data.PlacementCommandDate == null ? "" : raw_data.PlacementCommandDate.Value.ToThaiFullDate3(),
                    PlacementPositionName = raw_data.PlacementPositionName,
                    PlacementOrganizationName = raw_data.PlacementOrganizationName,
                    ProbationStartDate = raw_data.ProbationStartDate == null ? "" : raw_data.ProbationStartDate.Value.ToThaiFullDate3(),
                    ProbationEndDate = raw_data.ProbationEndDate == null ? "" : raw_data.ProbationEndDate.Value.ToThaiFullDate3(),
                    ChairManFullName = raw_data.ChairManFullName,
                    Member1FullName = raw_data.Member1FullName,
                    Member2FullName = raw_data.Member2FullName,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"10-แต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-11 "

        private async Task<byte[]> GenerateCommandReportType11_Cover(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType11Async(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"11-คำสั่งให้ข้าราชการที่ผ่านการประเมิน รับราชการต่อไป.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = data;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-12 "

        private async Task<byte[]> GenerateCommandReportType12_Cover(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType11Async(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"12-คำสั่งให้ข้าราชการที่ไม่ผ่านการประเมิน ออกจากราชการ.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = data;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-13 "

        private async Task<byte[]> GenerateCommandReportType13_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,

                    ReceiveOrganizationName = raw_data.ReceiveOrganizationName,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-1.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType13_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType13AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"27-คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ-2.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-14 "

        private async Task<byte[]> GenerateCommandReportType14_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,

                    TransferOrganizationName = raw_data.TransferOrganizationName,
                    ConclusionReceiveNo = raw_data.ConclusionReceiveNo,
                    ConclusionReceiveDate = raw_data.ConclusionReceiveDate == null ? "" : raw_data.ConclusionReceiveDate.Value.ToThaiFullDate3(),
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"28-คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ-5.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType14_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType14AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"28-คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ5-10.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-15 "

        private async Task<byte[]> GenerateCommandReportType15_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"29-คำสั่งให้ช่วยราชการ-1.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType15_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType15AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"29-คำสั่งให้ช่วยราชการ-2.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-16 "

        private async Task<byte[]> GenerateCommandReportType16_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                    GovAidCommandNo = raw_data.GovAidCommandNo,
                    GovAidCommandDate = raw_data.GovAidCommandDate == null ? "" : raw_data.GovAidCommandDate.Value.ToThaiFullDate3(),
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"30-คำสั่งส่งตัวกลับไปปฏิบัติงานทางต้นสังกัดเดิม.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-17 "

        private async Task<byte[]> GenerateCommandReportType17_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"34-คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ-4.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        private async Task<byte[]> GenerateCommandReportType17_Attachment(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType17AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"34-คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ-5.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = data;

                report.ReportParameters["IssuerOrganizationName"].Value = command.IssuerOrganizationName;
                report.ReportParameters["CommandNo"].Value = command.CommandNo;
                report.ReportParameters["CommandYear"].Value = command.CommandYear.ToInteger().ToThaiYear().ToString();
                report.ReportParameters["CommandExecuteDate"].Value = command.CommandExcecuteDate == null ? "" : command.CommandExcecuteDate.Value.ToThaiFullDate3();

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-18 "

        private async Task<byte[]> GenerateCommandReportType18_Cover(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType18Async(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"37-คำสั่งให้ออกจากราชการ.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = data;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-19 "

        private async Task<byte[]> GenerateCommandReportType19_Cover(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType19Async(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"37-คำสั่งปลดออกจากราชการ.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = data;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-20 "

        private async Task<byte[]> GenerateCommandReportType20_Cover(Guid commandId, string exportType)
        {
            try
            {
                var command = await _repository.GetByIdAsync(commandId);
                if (command == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                var data = await _commandReportRepository.GetCommandType20Async(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"38-คำสั่งลงโทษไล่ข้าราชการออกจากราชการ.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = data;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };

                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType, instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-21 "

        private async Task<byte[]> GenerateCommandReportType21_Cover(Guid commandId, string exportType)
        {
            try
            {
                var raw_data = await _repository.GetByIdAsync(commandId);
                if (raw_data == null)
                {
                    throw new Exception(GlobalMessages.CommandNotFound);
                }

                //var recvId = raw_data.Receivers.Select(x => x.RefPlacementProfileId).ToList();
                //var positionList = string.Empty;

                var command = new
                {
                    CommandNo = raw_data.CommandNo,
                    CommandYear = raw_data.CommandYear.ToInteger().ToThaiYear().ToString(),
                    IssuerOrganizationName = raw_data.IssuerOrganizationName,
                    ConclusionRegisterNo = raw_data.ConclusionRegisterNo,
                    ConclusionRegisterDate = raw_data.ConclusionRegisterDate == null ? "" : raw_data.ConclusionRegisterDate.Value.ToThaiFullDate3(),
                    ConclusionResultNo = raw_data.ConclusionResultNo,
                    ConclusionResultDate = raw_data.ConclusionResultDate == null ? "" : raw_data.ConclusionResultDate.Value.ToThaiFullDate3(),
                    PositionList = "",
                    Count = raw_data.Receivers.Count,
                    CommandAffectDate = raw_data.CommandAffectDate == null ? "" : raw_data.CommandAffectDate.Value.ToThaiFullDate3(),
                    AuthorizedUserFullName = raw_data.AuthorizedUserFullName,
                    AuthorizedPosition = raw_data.AuthorizedPosition,
                };


                var receiver = await _commandReportRepository.GetCommandType21AttachmentAsync(commandId);

                var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"20-คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ-2.trdp");

                ReportPackager reportPackager = new ReportPackager();
                Telerik.Reporting.Report? report = null;
                using (var sourceStream = System.IO.File.OpenRead(rptFile))
                {
                    report = (Telerik.Reporting.Report)reportPackager.UnpackageDocument(sourceStream);
                }

                report.DataSource = command;

                var tblData = (Telerik.Reporting.Table)report.Items["detailSection1"].Items["table1"];

                tblData.DataSource = receiver;

                System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
                if (exportType == "docx")
                    deviceInfo["OutputFormat"] = "DOCX";

                InstanceReportSource instanceReportSource = new InstanceReportSource()
                {
                    ReportDocument = report
                };


                ReportProcessor reportProcessor = new ReportProcessor(_configuration);
                RenderingResult result = reportProcessor.RenderReport(exportType.ToUpper(), instanceReportSource, deviceInfo);

                var content = result.DocumentBytes;

                return content;
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #endregion

        #region " C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้ "

        /// <summary>
        /// คำสั่ง C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-01/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType01CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType01_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-01 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้สอบแข่งขันได้
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-01/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType01AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType01_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-02 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก "

        /// <summary>
        /// คำสั่ง C-PM-02 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-02/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType02CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType02_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");


                //var rptFile = Path.Combine(_hostingEnvironment.ContentRootPath, "Reports", $"02-คำสั่งบรรจุและแต่งตั้งผู้ได้รับคัดเลือก-3.trdp");
                //var contentData = _reportGenerator.GenerateReport(rptFile, exportType);

                //return File(contentData, mimeType, $"command.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-02 คำสั่งบรรจุและแต่งตั้ง: สำหรับผู้ได้รับคัดเลือก
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-02/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType02AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType02_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-03 คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม "

        /// <summary>
        /// คำสั่ง C-PM-03 คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-03/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType03CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType03_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-03 คำสั่งแต่งตั้ง : สำหรับข้าราชการ กทม. เดิม
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-03/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType03AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType03_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-04 คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม "

        /// <summary>
        /// คำสั่ง C-PM-04 คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-04/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType04CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType04_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-04 คำสั่งย้าย : สำหรับข้าราชการ กทม. เดิม
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-04/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType04AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType04_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-05 คำสั่งแต่งตั้ง "

        /// <summary>
        /// คำสั่ง C-PM-05 คำสั่งแต่งตั้ง
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-05/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType05CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType05_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-05 คำสั่งแต่งตั้ง
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-05/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType05AttachmentReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType05_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-06 คำสั่งเลื่อน "

        /// <summary>
        /// คำสั่ง C-PM-06 คำสั่งเลื่อน
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-06/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType06CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType06_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-06 คำสั่งเลื่อน
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-06/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType06AttachmentReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType06_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-07 คำสั่งย้าย "

        /// <summary>
        /// คำสั่ง C-PM-07 คำสั่งย้าย
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-07/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType07CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType07_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-07 คำสั่งย้าย
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-07/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType07AttachmentReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType07_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-08 คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ "

        /// <summary>
        /// คำสั่ง C-PM-08 คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-08/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType08CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType08_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-08 คำสั่งบรรจุและแต่งตั้งข้าราชการฯ กลับเข้ารับราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-08/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType08AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType08_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-09 คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ "

        /// <summary>
        /// คำสั่ง C-PM-09 คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-09/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType09CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType09_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-09 คำสั่งบรรจุและแต่งตั้งผู้ออกไปรับราชการทหารกลับเข้ารับราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-09/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType09AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType09_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-10 คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ "

        /// <summary>
        /// คำสั่ง C-PM-10 คำสั่งแต่งตั้งคณะกรรมการประเมินผลการทดลองปฏิบัติหน้าที่ราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-10/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType10CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType10_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-11 คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป "

        /// <summary>
        /// คำสั่ง C-PM-11 คำสั่งให้ข้าราชการที่มีผลการทดลองปฏิบัติหน้าที่ราชการไม่ต่ำกว่ามาตรฐานที่กำหนดรับราชการต่อไป
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-11/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType11CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType11_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-12 คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด "

        /// <summary>
        /// คำสั่ง C-PM-12 คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-12/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType12CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType12_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-13 คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ "

        /// <summary>
        /// คำสั่ง C-PM-13 คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-13/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType13CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType13_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-13 คำสั่งให้โอนข้าราชการกรุงเทพมหานครสามัญ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-13/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType13AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType13_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-14 คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ "

        /// <summary>
        /// คำสั่ง C-PM-14 คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-14/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType14CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType14_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-14 คำสั่งรับโอนข้าราชการกรุงเทพมหานครสามัญ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-14/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType14AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType14_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-15 คำสั่งให้ช่วยราชการ "

        /// <summary>
        /// คำสั่ง C-PM-15 คำสั่งให้ช่วยราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-15/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType15CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType15_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-15 คำสั่งให้ช่วยราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-15/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType15AttachmentReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var contentData = await GenerateCommandReportType15_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-attachment-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-16 คำสั่งส่งตัวกลับ "

        /// <summary>
        /// คำสั่ง  C-PM-16 คำสั่งส่งตัวกลับ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-16/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType16CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType16_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-17 คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ "

        /// <summary>
        /// คำสั่ง C-PM-17 คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-17/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType17CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType17_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// เอกสารแนบท้าย C-PM-17 คำสั่งอนุญาตให้ข้าราชการลาออกจากราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-17/attachment/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType17AttachmentReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType17_Attachment(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-18 คำสั่งให้ออกจากราชการ "

        /// <summary>
        /// คำสั่ง  C-PM-18 คำสั่งให้ออกจากราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-18/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType18CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType18_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-19 คำสั่งปลดออกจากราชการ "

        /// <summary>
        /// คำสั่ง  C-PM-19 คำสั่งปลดออกจากราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-19/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType19CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType19_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-20 คำสั่งไล่ออกจากราชการ "

        /// <summary>
        /// คำสั่ง  C-PM-20 คำสั่งไล่ออกจากราชการ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-20/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType20CoverReport(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType20_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #region " C-PM-21 คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ "

        /// <summary>
        /// คำสั่ง C-PM-21 คำสั่งแต่งตั้งลูกจ้างชั่วคราวเป็นลูกจ้างประจำ
        /// </summary>
        /// <param name="id">Record Id ของคำสั่ง</param>
        /// <param name="exportType">pdf, docx หรือ xlsx</param>
        /// <returns></returns>
        /// <response code="200">เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ</response>
        /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
        /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
        [HttpGet("c-pm-21/cover/{exportType}/{id}")]
        [AllowAnonymous]
        [ProducesResponseType(StatusCodes.Status200OK)]
        [ProducesResponseType(StatusCodes.Status401Unauthorized)]
        [ProducesResponseType(StatusCodes.Status500InternalServerError)]
        public async Task<ActionResult<ResponseObject>> GetCommandType21CoverReportAsync(Guid id, string exportType = "pdf")
        {
            try
            {
                var mimeType = "";
                switch (exportType.Trim().ToLower())
                {
                    case "pdf": mimeType = "application/pdf"; break;
                    case "docx": mimeType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
                    case "xlsx": mimeType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
                }

                var cmd = await _repository.GetByIdAsync(id);
                if (cmd == null)
                    throw new Exception(GlobalMessages.CommandNotFound);

                var contentData = await GenerateCommandReportType21_Cover(id, exportType);
                return File(contentData, mimeType, $"command-{cmd.CommandNo}-{cmd.CommandYear.ToInteger().ToThaiYear()}.{exportType.Trim().ToLower()}");
            }
            catch
            {
                throw;
            }
        }

        #endregion

        #endregion
    }
}
