using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories.MessageQueue; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Placement.Service.Requests; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Swashbuckle.AspNetCore.Annotations; using System.Security.Claims; using System.Net.Http.Headers; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using static Microsoft.EntityFrameworkCore.DbLoggerCategory; using BMA.EHR.Application.Repositories.Reports; using System.Text.RegularExpressions; namespace BMA.EHR.Placement.Service.Controllers { [Route("api/v{version:apiVersion}/placement")] [ApiVersion("1.0")] [ApiController] [Produces("application/json")] [Authorize] [SwaggerTag("ระบบบรรจุ")] public class PlacementController : BaseController { private readonly PlacementRepository _repository; private readonly NotificationRepository _repositoryNoti; private readonly ApplicationDBContext _context; private readonly MinIOService _documentService; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IConfiguration _configuration; private readonly PermissionRepository _permission; private readonly CandidateReportRepository _service; private readonly MinIOExamService _minIOExamService; public PlacementController(PlacementRepository repository, NotificationRepository repositoryNoti, ApplicationDBContext context, MinIOService documentService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration, PermissionRepository permission, CandidateReportRepository service, MinIOExamService minIOExamService) { _repository = repository; _repositoryNoti = repositoryNoti; _context = context; _documentService = documentService; _httpContextAccessor = httpContextAccessor; _configuration = configuration; _permission = permission; _service = service; _minIOExamService = minIOExamService; } #region " Properties " private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value; private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value; private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"]; //private bool isSuperAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("SUPER_ADMIN") ?? false; #endregion [HttpGet] public async Task> Get() { var data = await _repository.GetAllAsync(); return Success(data); } [HttpGet("fiscal")] public async Task> GetFiscal() { var data = await _repository.GetAllAsync(); if (data != null) { var _data = data.GroupBy(x => x.Year).Select(x => new { Id = x.FirstOrDefault().Year, Name = x.FirstOrDefault().Year + 543, }).OrderByDescending(x => x.Id).ToList(); return Success(_data); } return Success(data); } [HttpGet("exam/{year}")] public async Task> GetExam(int year) // public async Task> GetExam(int year, int page = 1, int pageSize = 10, string keyword = "") { var getPermission = await _permission.GetPermissionAPIAsync("LIST", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var data = await _context.Placements.Where(x => year > 0 ? (x.Year == year) : (x.Year > 0)) .OrderByDescending(x => x.CreatedAt) .Select(x => new { Id = x.Id, ExamRound = x.Name, ExamOrder = x.Round, FiscalYear = x.Year + 543, NumberOfCandidates = x.PlacementProfiles.Count(), ExamTypeValue = x.PlacementType.Id, ExamTypeName = x.PlacementType.Name, AccountStartDate = x.StartDate, AccountEndDate = x.EndDate, AccountExpirationDate = x.EndDate, IsExpired = x.EndDate.Date < DateTime.Now.Date, CreatedAt = x.CreatedAt, }).ToListAsync(); // if (keyword != "") // { // var data_ = data.Where(x => // (x.ExamRound != null && x.ExamRound.Contains(keyword)) || // (x.ExamOrder != null && x.ExamOrder.Contains(keyword)) || // (x.NumberOfCandidates != null && x.NumberOfCandidates.ToString().Contains(keyword))) // .OrderByDescending(x => x.CreatedAt) // .Skip((page - 1) * pageSize) // .Take(pageSize) // .ToList(); // data = data_; // } return Success(data); } [HttpGet("pass/{examId:length(36)}")] public async Task> GetExamByPlacement(Guid examId) { var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(examId.ToString(), "SYS_PLACEMENT_PASS"); if (getWorkflow == false) { var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } } var rootId = ""; var child1Id = ""; var child2Id = ""; var child3Id = ""; var child4Id = ""; var rootDnaId = ""; var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position-act"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { var org = JsonConvert.DeserializeObject(_result); if (org.result.isOfficer == false) { rootId = org.result.rootId == null ? "" : org.result.rootId; // child1Id = org.result.child1Id == null ? "" : org.result.child1Id; // child2Id = org.result.child2Id == null ? "" : org.result.child2Id; // child3Id = org.result.child3Id == null ? "" : org.result.child3Id; // child4Id = org.result.child4Id == null ? "" : org.result.child4Id; rootDnaId = org.result.rootDnaId == null ? "" : org.result.rootDnaId; var data1 = await _context.PlacementProfiles .Where(x => x.Placement.Id == examId) .Where(x => x.Draft == true) .Where(x => x.PlacementStatus != "UN-CONTAIN") .Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))) .Select(x => new { Id = x.Id, PersonalId = x.Id, x.profileId, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", Prefix = x.Prefix, Firstname = x.Firstname, Lastname = x.Lastname, IdCard = x.CitizenId, CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, rootIdOld = x.rootIdOld, root = x.root, rootId = x.rootId, rootShortName = x.rootShortName, child1 = x.child1, child1Id = x.child1Id, child1ShortName = x.child1ShortName, child2 = x.child2, child2Id = x.child2Id, child2ShortName = x.child2ShortName, child3 = x.child3, child3Id = x.child3Id, child3ShortName = x.child3ShortName, child4 = x.child4, child4Id = x.child4Id, child4ShortName = x.child4ShortName, orgRevisionId = x.orgRevisionId, positionId = x.positionId, posMasterNo = x.posMasterNo, positionName = x.positionName, positionField = x.positionField, posTypeId = x.posTypeId, posTypeName = x.posTypeName, posLevelId = x.posLevelId, posLevelName = x.posLevelName, ReportingDate = x.ReportingDate, StatusId = x.PlacementStatus, Draft = x.Draft, typeCommand = x.typeCommand, IsOfficer = x.IsOfficer, IsRelief = x.IsRelief, posLevelCandidate = x.PositionLevel, posTypeCandidate = x.PositionType, positionCandidate = x.PositionCandidate, x.commandId, x.refCommandCode, x.refCommandDate, x.refCommandName, x.refCommandNo, x.templateDoc, }).OrderBy(x => x.ExamNumber).ToListAsync(); var result1 = new List(); foreach (var p in data1) { var _data1 = new { p.Id, p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, p.Prefix, p.Firstname, p.Lastname, p.IdCard, p.CitizenId, p.profileId, p.ExamNumber, p.posmasterId, p.rootIdOld, p.root, p.rootId, p.rootShortName, p.child1, p.child1Id, p.child1ShortName, p.child2, p.child2Id, p.child2ShortName, p.child3, p.child3Id, p.child3ShortName, p.child4, p.child4Id, p.child4ShortName, node = p.root == null ? (int?)null : (p.child1 == null ? 0 : (p.child2 == null ? 1 : (p.child3 == null ? 2 : (p.child4 == null ? 3 : 4)))), nodeName = p.root == null ? null : (p.child1 == null ? p.root : (p.child2 == null ? p.child1 : (p.child3 == null ? p.child2 : (p.child4 == null ? p.child3 : p.child4)))), nodeId = p.rootId == null ? null : (p.child1Id == null ? p.rootId : (p.child2Id == null ? p.child1Id : (p.child3Id == null ? p.child2Id : (p.child4Id == null ? p.child3Id : p.child4Id)))), nodeShortName = p.rootShortName == null ? null : (p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName)))), p.orgRevisionId, p.positionId, p.posMasterNo, p.positionName, p.positionField, p.posTypeId, p.posTypeName, p.posLevelId, p.posLevelName, p.ReportingDate, BmaOfficer = p.IsOfficer == true ? "OFFICER" : null, p.StatusId, p.Draft, p.typeCommand, p.IsRelief, p.posLevelCandidate, p.posTypeCandidate, p.positionCandidate, p.commandId, p.refCommandCode, p.refCommandDate, p.refCommandName, p.refCommandNo, p.templateDoc, }; result1.Add(_data1); } return Success(result1); } if (org.result.isOfficer == true) { var data = await _context.PlacementProfiles.Where(x => x.Placement.Id == examId).Select(x => new { Id = x.Id, PersonalId = x.Id, x.profileId, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", Prefix = x.Prefix, Firstname = x.Firstname, Lastname = x.Lastname, IdCard = x.CitizenId, CitizenId = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, rootIdOld = x.rootIdOld, root = x.root, rootId = x.rootId, rootShortName = x.rootShortName, child1 = x.child1, child1Id = x.child1Id, child1ShortName = x.child1ShortName, child2 = x.child2, child2Id = x.child2Id, child2ShortName = x.child2ShortName, child3 = x.child3, child3Id = x.child3Id, child3ShortName = x.child3ShortName, child4 = x.child4, child4Id = x.child4Id, child4ShortName = x.child4ShortName, orgRevisionId = x.orgRevisionId, positionId = x.positionId, posMasterNo = x.posMasterNo, positionName = x.positionName, positionField = x.positionField, posTypeId = x.posTypeId, posTypeName = x.posTypeName, posLevelId = x.posLevelId, posLevelName = x.posLevelName, ReportingDate = x.ReportingDate, StatusId = x.PlacementStatus, Draft = x.Draft, typeCommand = x.typeCommand, IsOfficer = x.IsOfficer, IsRelief = x.IsRelief, posLevelCandidate = x.PositionLevel, posTypeCandidate = x.PositionType, positionCandidate = x.PositionCandidate, x.commandId, x.refCommandCode, x.refCommandDate, x.refCommandName, x.refCommandNo, x.templateDoc, }).OrderBy(x => x.ExamNumber).ToListAsync(); var result = new List(); foreach (var p in data) { var _data = new { p.Id, p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, p.Prefix, p.Firstname, p.Lastname, p.IdCard, p.CitizenId, p.profileId, p.ExamNumber, p.posmasterId, p.rootIdOld, p.root, p.rootId, p.rootShortName, p.child1, p.child1Id, p.child1ShortName, p.child2, p.child2Id, p.child2ShortName, p.child3, p.child3Id, p.child3ShortName, p.child4, p.child4Id, p.child4ShortName, node = p.root == null ? (int?)null : (p.child1 == null ? 0 : (p.child2 == null ? 1 : (p.child3 == null ? 2 : (p.child4 == null ? 3 : 4)))), nodeName = p.root == null ? null : (p.child1 == null ? p.root : (p.child2 == null ? p.child1 : (p.child3 == null ? p.child2 : (p.child4 == null ? p.child3 : p.child4)))), nodeId = p.rootId == null ? null : (p.child1Id == null ? p.rootId : (p.child2Id == null ? p.child1Id : (p.child3Id == null ? p.child2Id : (p.child4Id == null ? p.child3Id : p.child4Id)))), nodeShortName = p.rootShortName == null ? null : (p.child1ShortName == null ? p.rootShortName : (p.child2ShortName == null ? p.child1ShortName : (p.child3ShortName == null ? p.child2ShortName : (p.child4ShortName == null ? p.child3ShortName : p.child4ShortName)))), p.orgRevisionId, p.positionId, p.posMasterNo, p.positionName, p.positionField, p.posTypeId, p.posTypeName, p.posLevelId, p.posLevelName, p.ReportingDate, BmaOfficer = p.IsOfficer == true ? "OFFICER" : null, p.StatusId, p.Draft, p.typeCommand, p.IsRelief, p.posLevelCandidate, p.posTypeCandidate, p.positionCandidate, p.commandId, p.refCommandCode, p.refCommandDate, p.refCommandName, p.refCommandNo, p.templateDoc, }; result.Add(_data); } return Success(result); } } } return Success(new List()); } [HttpGet("exam-probation/{citizenId:length(13)}")] public async Task> GetDataExamByPlacement(string citizenId) { var dateAppoint = string.Empty; var apiUrl = $"{_configuration["API"]}/org/profile/citizenid/position/{citizenId}"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { var json = JObject.Parse(_result); var dateAppointToken = json["result"]?["dateAppoint"]; if (dateAppointToken != null) { dateAppoint = dateAppointToken.ToString(); } } } var placementProfile = await _context.PlacementProfiles .Include(x => x.Placement) .Select(x => new { fullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", citizenId = x.CitizenId, examName = x.Placement.Name, }) .Where(x => x.citizenId == citizenId.ToString()) .FirstOrDefaultAsync(); var data = new { fullName = placementProfile != null ? placementProfile.fullName : "", citizenId = placementProfile != null ? placementProfile.citizenId : "", examName = placementProfile != null ? placementProfile.examName : "", dateAppoint = dateAppoint }; return Success(data); } [HttpGet("personal/{personalId:length(36)}")] public async Task> GetProfileByUser(Guid personalId) { var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); if (person.IsProperty == null || Newtonsoft.Json.JsonConvert.DeserializeObject>(person.IsProperty).Count() == 0) { var isProperty = await _context.PlacementIsProperties.Select(x => new PersonPropertyRequest { Name = x.Name, Value = false, }).ToListAsync(); person.IsProperty = Newtonsoft.Json.JsonConvert.SerializeObject(isProperty); person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); } var data = await _context.PlacementProfiles.Select(x => new { PersonalId = x.Id, IdCard = x.CitizenId, Prefix = x.Prefix, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", Firstname = x.Firstname, Lastname = x.Lastname, Nationality = x.Nationality, Draft = x.Draft, Race = x.Race, DateOfBirth = x.DateOfBirth, Age = x.DateOfBirth == null ? null : x.DateOfBirth.Value.CalculateAgeStrV2(0, 0), Telephone = x.Telephone, PositionCandidate = x.PositionCandidate, Gender = x.Gender, Relationship = x.Relationship, BloodGroup = x.BloodGroup, Religion = x.Religion, // Address = $"{x.RegistAddress}" + // (x.RegistSubDistrict == null ? null : " แขวง") + (x.RegistSubDistrict == null ? null : x.RegistSubDistrict.Name) + // (x.RegistDistrict == null ? null : " เขต") + (x.RegistDistrict == null ? null : x.RegistDistrict.Name) + // (x.RegistProvince == null ? null : " จังหวัด") + (x.RegistProvince == null ? null : x.RegistProvince.Name) + // (x.RegistSubDistrict == null ? null : " ") + (x.RegistSubDistrict == null ? null : x.RegistSubDistrict.ZipCode), Education = x.PlacementEducations.Select(p => new { Id = p.Id, EducationLevel = p.EducationLevelName, EducationLevelId = p.EducationLevelId, Institute = p.Institute, Degree = p.Degree, Field = p.Field, Gpa = p.Gpa, Country = p.Country, Duration = p.Duration, Other = p.Other, FundName = p.FundName, DurationYear = p.DurationYear, FinishDate = p.FinishDate, IsDate = p.IsDate, StartDate = p.StartDate, EndDate = p.EndDate, PositionPath = p.PositionPath == null ? null : p.PositionPath.Name, PositionPathId = p.PositionPath == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPath.Id, IsEducation = p.IsEducation, }), RegistAddress = x.RegistAddress, RegistSubDistrictId = x.RegistSubDistrictId, RegistZipCode = x.RegistZipCode, RegistDistrictId = x.RegistDistrictId, RegistProvinceId = x.RegistProvinceId, CurrentAddress = x.CurrentAddress, CurrentSubDistrictId = x.CurrentSubDistrictId, CurrentZipCode = x.CurrentZipCode, CurrentDistrictId = x.CurrentDistrictId, CurrentProvinceId = x.CurrentProvinceId, RegistSame = x.RegistSame, MarryPrefix = x.MarryPrefix, Couple = x.Marry, MarryFirstName = x.MarryFirstName, MarryLastName = x.MarryLastName, MarryOccupation = x.MarryOccupation, FatherPrefix = x.FatherPrefix, FatherFirstName = x.FatherFirstName, FatherLastName = x.FatherLastName, FatherOccupation = x.FatherOccupation, MotherPrefix = x.MotherPrefix, MotherFirstName = x.MotherFirstName, MotherLastName = x.MotherLastName, MotherOccupation = x.MotherOccupation, Certificates = x.PlacementCertificates.Select(p => new { Id = p.Id, CertificateNo = p.CertificateNo, Issuer = p.Issuer, IssueDate = p.IssueDate, ExpireDate = p.ExpireDate, CertificateType = p.CertificateType, }), PointA = x.PointA, PointB = x.PointB, PointC = x.PointC, PointTotalA = x.PointTotalA, PointTotalB = x.PointTotalB, PointTotalC = x.PointTotalC, Point = x.PointA + x.PointB + x.PointC, PointTotal = x.PointTotalA + x.PointTotalB + x.PointTotalC, ExamNumber = x.ExamNumber, ExamRound = x.ExamRound, Pass = x.Pass, IsRelief = x.IsRelief, IsProperty = x.IsProperty == null ? null : Newtonsoft.Json.JsonConvert.DeserializeObject>(x.IsProperty), BmaOfficer = x.IsOfficer == true ? "OFFICER" : null, PlacementProfileDocs = x.PlacementProfileDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }), }).FirstOrDefaultAsync(x => x.PersonalId == personalId); if (data == null) return Error(GlobalMessages.DataNotFound, 404); var placementProfileDocs = new List(); foreach (var doc in data.PlacementProfileDocs) { var _doc = new { doc.FileName, PathName = await _documentService.ImagesPath(doc.Id), docId = doc.Id, }; placementProfileDocs.Add(_doc); } var _data = new { data.PersonalId, data.IdCard, data.Prefix, data.FullName, data.Firstname, data.Lastname, data.Draft, data.Nationality, data.Race, data.DateOfBirth, data.Age, data.Telephone, data.PositionCandidate, data.Gender, data.Relationship, data.BloodGroup, data.Religion, // data.Address, data.Education, data.RegistAddress, data.RegistSubDistrictId, data.RegistZipCode, data.RegistDistrictId, data.RegistProvinceId, data.CurrentAddress, data.CurrentSubDistrictId, data.CurrentZipCode, data.CurrentDistrictId, data.CurrentProvinceId, data.RegistSame, data.MarryPrefix, data.Couple, data.MarryFirstName, data.MarryLastName, data.MarryOccupation, data.FatherPrefix, data.FatherFirstName, data.FatherLastName, data.FatherOccupation, data.MotherPrefix, data.MotherFirstName, data.MotherLastName, data.MotherOccupation, data.Certificates, data.PointA, data.PointB, data.PointC, data.PointTotalA, data.PointTotalB, data.PointTotalC, data.Point, data.PointTotal, data.ExamNumber, data.ExamRound, data.Pass, data.IsProperty, data.IsRelief, BmaOfficer = data.BmaOfficer, Docs = placementProfileDocs, }; return Success(_data); } [HttpPut("property/{personalId:length(36)}")] public async Task> UpdatePropertyByUser([FromBody] List req, Guid personalId) { var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.IsProperty = Newtonsoft.Json.JsonConvert.SerializeObject(req); person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); return Success(); } [HttpGet("pass/stat/{examId:length(36)}")] public async Task> GetDashboardByPlacement(Guid examId) { var rootId = ""; var child1Id = ""; var child2Id = ""; var child3Id = ""; var child4Id = ""; var rootDnaId = ""; var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position-act"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { var org = JsonConvert.DeserializeObject(_result); if (org.result.isOfficer == false) { rootId = org.result.rootId == null ? "" : org.result.rootId; // child1Id = org.result.child1Id == null ? "" : org.result.child1Id; // child2Id = org.result.child2Id == null ? "" : org.result.child2Id; // child3Id = org.result.child3Id == null ? "" : org.result.child3Id; // child4Id = org.result.child4Id == null ? "" : org.result.child4Id; rootDnaId = org.result.rootDnaId == null ? "" : org.result.rootDnaId; var placement = await _context.Placements .Where(x => x.Id == examId) .Select(x => new { Total = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Count(), UnContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(), PrepareContain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(), Report = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "REPORT").Count(), Done = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "DONE").Count(), Disclaim = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootDnaId == "" ? true : (child1Id == "" ? x.rootDnaId == rootDnaId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(), }).FirstOrDefaultAsync(); if (placement == null) return Error(GlobalMessages.DataNotFound, 404); return Success(placement); } if (org.result.isOfficer == true) { var placement = await _context.Placements .Where(x => x.Id == examId) .Select(x => new { Total = x.PlacementProfiles.Count(), UnContain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "UN-CONTAIN").Count(), PrepareContain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(), Report = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "REPORT").Count(), Done = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "DONE").Count(), Disclaim = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(), }).FirstOrDefaultAsync(); if (placement == null) return Error(GlobalMessages.DataNotFound, 404); return Success(placement); } } } return Success(new List()); } [HttpPost("pass/deferment"), DisableRequestSizeLimit] public async Task> UpdatePersonDeferment([FromForm] PersonDefermentRequest req) { var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var person = await _context.PlacementProfiles.FindAsync(Request.Form.ContainsKey("personalId") ? Guid.Parse(Request.Form["personalId"]) : Guid.Parse("00000000-0000-0000-0000-000000000000")); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.IsRelief = true; person.ReliefReason = Request.Form.ContainsKey("note") ? Request.Form["note"] : ""; person.PlacementStatus = "PREPARE-CONTAIN"; if (Request.Form.Files != null && Request.Form.Files.Count != 0) { var file = Request.Form.Files[0]; var fileExtension = Path.GetExtension(file.FileName); var doc = await _documentService.UploadFileAsync(file, file.FileName); person.ReliefDoc = doc; } person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); return Success(); } [HttpPost("pass/disclaim")] public async Task> UpdatePersonDisclaim([FromBody] PersonDisclaimRequest req) { var getPermission = await _permission.GetPermissionAPIAsync("CREATE", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var person = await _context.PlacementProfiles .FirstOrDefaultAsync(x => x.Id == req.PersonalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); bool? _nullBool = null; //person.PositionLevel = null; //person.PositionType = null; //person.Amount = null; //person.MouthSalaryAmount = null; //person.PositionSalaryAmount = null; //person.RecruitDate = null; //person.ReportingDate = null; person.RejectReason = req.Note; person.PlacementStatus = "DISCLAIM"; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; //person.root = null; //person.rootId = null; //person.rootDnaId = null; //person.rootShortName = null; //person.child1 = null; //person.child1Id = null; //person.child1DnaId = null; //person.child1ShortName = null; //person.child2 = null; //person.child2Id = null; //person.child2Id = null; //person.child2ShortName = null; //person.child3 = null; //person.child3Id = null; //person.child3DnaId = null; //person.child3ShortName = null; //person.child4 = null; //person.child4Id = null; //person.child4DnaId = null; //person.child4ShortName = null; //person.orgRevisionId = null; //person.posMasterNo = null; //person.positionName = null; //person.positionField = null; //person.posTypeId = null; //person.posTypeName = null; //person.posLevelId = null; //person.posLevelName = null; //person.node = null; //person.nodeId = null; //person.posmasterId = null; //person.positionId = null; //person.Draft = _nullBool; //person.typeCommand = null; await _context.SaveChangesAsync(); return Success(); } /// /// API อัพเดทสถานะเป็นบรรจุ /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("pass/update-status")] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PersonUpdateStatus([FromBody] PersonUpdateStatusRequest req) { var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } string role = jsonData["result"]?.ToString(); if (role != "OWNER") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var person = await _context.PlacementProfiles .FirstOrDefaultAsync(x => x.Id == req.PersonalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.PlacementStatus = "DONE"; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); return Success(); } [HttpGet("pass/deferment/{personalId:length(36)}")] public async Task> GetPersonDeferment(Guid personalId) { var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(personalId.ToString(), "SYS_PLACEMENT_PASS"); if (getWorkflow == false) { var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } } var person = await _context.PlacementProfiles.Include(x => x.ReliefDoc).FirstOrDefaultAsync(x => x.Id == personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var data = new { ReliefReason = person.ReliefReason, ReliefDoc = person.ReliefDoc == null ? null : await _documentService.ImagesPath(person.ReliefDoc.Id), }; return Success(data); } [HttpGet("pass/disclaim/{personalId:length(36)}")] public async Task> GetPersonDisclaim(Guid personalId) { var getWorkflow = await _permission.GetPermissionAPIWorkflowAsync(personalId.ToString(), "SYS_PLACEMENT_PASS"); if (getWorkflow == false) { var getPermission = await _permission.GetPermissionAPIAsync("GET", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } } var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var data = new { RejectReason = person.RejectReason, }; return Success(data); } [HttpPost("pass")] public async Task> UpdatePositionByPerson([FromBody] PersonSelectPositionRequest req) { var person = await _context.PlacementProfiles.FindAsync(req.personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); if (person.Draft == true) return Error("ไม่สามารถแก้ไขข้อมูลนี้ได้เนื่องจากเผยแพร่ไปแล้ว"); var apiUrl = $"{_configuration["API"]}/org/find/all"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); var _res = await client.PostAsJsonAsync(apiUrl, new { node = req.node, nodeId = req.nodeId, }); var _result = await _res.Content.ReadAsStringAsync(); var org = JsonConvert.DeserializeObject(_result); if (org == null || org.result == null) return Error("ไม่พบหน่วยงานนี้ในระบบ", 404); person.root = org.result.root; person.rootId = org.result.rootId; person.rootDnaId = org.result.rootDnaId; person.rootShortName = org.result.rootShortName; person.child1 = req.node <= 0 ? null : org.result.child1; person.child1Id = req.node <= 0 ? null : org.result.child1Id; person.child1DnaId = req.node <= 0 ? null : org.result.child1DnaId; person.child1ShortName = req.node <= 0 ? null : org.result.child1ShortName; person.child2 = req.node <= 1 ? null : org.result.child2; person.child2Id = req.node <= 1 ? null : org.result.child2Id; person.child2DnaId = req.node <= 1 ? null : org.result.child2DnaId; person.child2ShortName = req.node <= 1 ? null : org.result.child2ShortName; person.child3 = req.node <= 2 ? null : org.result.child3; person.child3Id = req.node <= 2 ? null : org.result.child3Id; person.child3DnaId = req.node <= 2 ? null : org.result.child3DnaId; person.child3ShortName = req.node <= 2 ? null : org.result.child3ShortName; person.child4 = req.node <= 3 ? null : org.result.child4; person.child4Id = req.node <= 3 ? null : org.result.child4Id; person.child4DnaId = req.node <= 3 ? null : org.result.child4DnaId; person.child4ShortName = req.node <= 3 ? null : org.result.child4ShortName; } var apiUrlUpdate = $"{_configuration["API"]}/org/pos/officer/master/book"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _resUpdate = await client.PostAsJsonAsync(apiUrlUpdate, new { posMasterId = req.posmasterId, profileId = person.profileId, }); } person.Draft = false; person.typeCommand = req.typeCommand == null ? null : req.typeCommand.Trim().ToUpper(); person.ReportingDate = req.reportingDate; person.posmasterId = req.posmasterId; person.node = req.node; person.nodeId = req.nodeId; person.orgRevisionId = req.orgRevisionId; person.positionId = req.positionId; person.posMasterNo = req.posMasterNo; person.positionName = req.positionName; person.PositionExecutive = req.posExecutiveName; person.positionExecutiveField = req.positionExecutiveField; person.positionArea = req.positionArea; person.positionField = req.positionField; person.posTypeId = req.posTypeId; person.posTypeName = req.posTypeName; person.posLevelId = req.posLevelId; person.posLevelName = req.posLevelName; if (person.profileId != null && person.profileId != "") { apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{person.profileId}"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); var org = JsonConvert.DeserializeObject(_result); if (org == null || org.result == null) { person.IsOld = false; } else { person.nodeOld = org.result.node; person.nodeIdOld = org.result.nodeId; person.rootOld = org.result.root; person.rootIdOld = org.result.rootId; person.rootShortNameOld = org.result.rootShortName; person.child1Old = org.result.child1; person.child1IdOld = org.result.child1Id; person.child1ShortNameOld = org.result.child1ShortName; person.child2Old = org.result.child2; person.child2IdOld = org.result.child2Id; person.child2ShortNameOld = org.result.child2ShortName; person.child3Old = org.result.child3; person.child3IdOld = org.result.child3Id; person.child3ShortNameOld = org.result.child3ShortName; person.child4Old = org.result.child4; person.child4IdOld = org.result.child4Id; person.child4ShortNameOld = org.result.child4ShortName; person.posMasterNoOld = org.result.posMasterNo; person.positionNameOld = org.result.position; person.posTypeIdOld = org.result.posTypeId; person.posTypeNameOld = org.result.posTypeName; person.posLevelIdOld = org.result.posLevelId; person.posLevelNameOld = org.result.posLevelName; } } } person.PlacementStatus = "PREPARE-CONTAIN"; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } [HttpPut("information/{personalId:length(36)}")] public async Task> UpdateInformation([FromBody] PersonInformationRequest req, Guid personalId) { var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.Prefix = req.Prefix; person.Gender = req.Gender; person.Relationship = req.Relationship; person.BloodGroup = req.BloodGroup; person.Religion = req.Religion; person.CitizenId = req.CitizenId; person.Firstname = req.FirstName; person.Lastname = req.LastName; person.Nationality = req.Nationality; person.Race = req.Race; person.DateOfBirth = req.BirthDate; person.Telephone = req.TelephoneNumber; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } [HttpPut("address/{personalId:length(36)}")] public async Task> UpdateAddress([FromBody] PersonAddressRequest req, Guid personalId) { var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.RegistSubDistrictId = req.RegistrationSubDistrictId; person.RegistZipCode = req.RegistrationZipCode; person.RegistDistrictId = req.RegistrationDistrictId; person.RegistProvinceId = req.RegistrationProvinceId; person.CurrentSubDistrictId = req.CurrentSubDistrictId; person.CurrentZipCode = req.CurrentZipCode; person.CurrentDistrictId = req.CurrentDistrictId; person.CurrentProvinceId = req.CurrentProvinceId; person.CurrentAddress = req.CurrentAddress; person.RegistAddress = req.RegistrationAddress; person.RegistSame = req.RegistrationSame; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } [HttpPut("family/{personalId:length(36)}")] public async Task> UpdateFamily([FromBody] PersonFamilyRequest req, Guid personalId) { var person = await _context.PlacementProfiles.FindAsync(personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.MotherPrefix = req.MotherPrefix; person.FatherPrefix = req.FatherPrefix; person.MarryPrefix = req.CouplePrefix; person.Marry = req.Couple; person.MarryFirstName = req.CoupleFirstName; person.MarryLastName = req.CoupleLastName; // person.MarryLastNameOld = req.CoupleLastNameOld; person.MarryOccupation = req.CoupleCareer; // person.MarryCitizenId = req.CoupleCitizenId; // person.MarryLive = req.CoupleLive; person.FatherFirstName = req.FatherFirstName; person.FatherLastName = req.FatherLastName; person.FatherOccupation = req.FatherCareer; // person.FatherCitizenId = req.FatherCitizenId; // person.FatherLive = req.FatherLive; person.MotherFirstName = req.MotherFirstName; person.MotherLastName = req.MotherLastName; person.MotherOccupation = req.MotherCareer; // person.MotherCitizenId = req.MotherCitizenId; // person.MotherLive = req.MotherLive; person.LastUpdateFullName = FullName ?? "System Administrator"; person.LastUpdateUserId = UserId ?? ""; person.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } [HttpPost("certificate/{personalId:length(36)}")] public async Task> CreateCertificate([FromBody] PersonCertificateRequest req, Guid personalId) { var person = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .FirstOrDefaultAsync(x => x.Id == personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var data = new PlacementCertificate { PlacementProfile = person, CertificateNo = req.CertificateNo, Issuer = req.Issuer, IssueDate = req.IssueDate, ExpireDate = req.ExpireDate, CertificateType = req.CertificateType, CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", CreatedAt = DateTime.Now, LastUpdateFullName = FullName ?? "System Administrator", LastUpdateUserId = UserId ?? "", LastUpdatedAt = DateTime.Now, }; await _context.PlacementCertificates.AddAsync(data); _context.SaveChanges(); return Success(); } [HttpPut("certificate/{personalId:length(36)}")] public async Task> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId) { var person = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .FirstOrDefaultAsync(x => x.Id == personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == req.Id); if (certificate == null) return Error(GlobalMessages.CertificateNotFound, 404); certificate.CertificateNo = req.CertificateNo; certificate.Issuer = req.Issuer; certificate.IssueDate = req.IssueDate; certificate.ExpireDate = req.ExpireDate; certificate.CertificateType = req.CertificateType; certificate.LastUpdateFullName = FullName ?? "System Administrator"; certificate.LastUpdateUserId = UserId ?? ""; certificate.LastUpdatedAt = DateTime.Now; _context.SaveChanges(); return Success(); } [HttpDelete("certificate/{personalId:length(36)}/{certificateId:length(36)}")] public async Task> DeleteCertificate(Guid personalId, Guid certificateId) { var person = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .FirstOrDefaultAsync(x => x.Id == personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == certificateId); if (certificate == null) return Error(GlobalMessages.CertificateNotFound, 404); _context.PlacementCertificates.Remove(certificate); _context.SaveChanges(); return Success(); } [HttpPost("education/{personalId:length(36)}")] public async Task> CreateEducation([FromBody] PersonEducationRequest req, Guid personalId) { var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); var positionPath = await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == req.PositionPathId); if (positionPath == null && req.PositionPathId != null) return Error(GlobalMessages.DataNotFound, 404); var data = new PlacementEducation { PlacementProfile = profile, EducationLevelId = req.EducationLevelId, EducationLevelName = req.EducationLevelName, PositionPath = positionPath, Institute = req.Institute, Degree = req.Degree, Field = req.Field, Gpa = req.Gpa, Country = req.Country, Duration = req.Duration, DurationYear = req.DurationYear, Other = req.Other, FundName = req.FundName, IsDate = req.IsDate, FinishDate = req.FinishDate, StartDate = req.StartDate, EndDate = req.EndDate, CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", CreatedAt = DateTime.Now, LastUpdateFullName = FullName ?? "System Administrator", LastUpdateUserId = UserId ?? "", LastUpdatedAt = DateTime.Now, }; await _context.PlacementEducations.AddAsync(data); await _context.SaveChangesAsync(); return Success(); } [HttpPut("education/{personalId:length(36)}")] public async Task> UpdateEducation([FromBody] PersonEducationRequest req, Guid personalId) { var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); var positionPath = await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == req.PositionPathId); if (positionPath == null && req.PositionPathId != null) return Error(GlobalMessages.DataNotFound, 404); var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id); if (education == null) return Error(GlobalMessages.EducationNotFound, 404); education.EducationLevelId = req.EducationLevelId; education.EducationLevelName = req.EducationLevelName; education.PositionPath = positionPath; education.Institute = req.Institute; education.Degree = req.Degree; education.Field = req.Field; education.Gpa = req.Gpa; education.Country = req.Country; education.Duration = req.Duration; education.DurationYear = req.DurationYear; education.Other = req.Other; education.FundName = req.FundName; education.IsDate = req.IsDate; education.FinishDate = req.FinishDate; education.StartDate = req.StartDate; education.EndDate = req.EndDate; education.LastUpdateFullName = FullName ?? "System Administrator"; education.LastUpdateUserId = UserId ?? ""; education.LastUpdatedAt = DateTime.Now; await _context.SaveChangesAsync(); return Success(); } [HttpDelete("education/{educationId:length(36)}")] public async Task> DeleteEducation(Guid educationId) { var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == educationId); if (education == null) return Error(GlobalMessages.EducationNotFound, 404); _context.PlacementEducations.Remove(education); _context.SaveChanges(); return Success(); } [HttpPut("position/{personalId:length(36)}")] public async Task> UpdatePositionDraft([FromBody] List items, Guid personalId) { var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var placement = await _context.Placements .FirstOrDefaultAsync(x => x.Id == personalId); if (placement == null) return Error(GlobalMessages.DataNotFound, 404); foreach (var item in items) { var profile = await _context.PlacementProfiles .FirstOrDefaultAsync(x => x.Id == item); if (profile != null) profile.Draft = true; } _context.SaveChanges(); return Success(); } [HttpPost("position/clear/{personalId:length(36)}")] public async Task> UpdatePositionDraft(Guid personalId) { var profile = await _context.PlacementProfiles .FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); var apiUrlUpdate = $"{_configuration["API"]}/org/pos/officer/master/clear"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _resUpdate = await client.PostAsJsonAsync(apiUrlUpdate, new { posMasterId = profile.posmasterId, }); } profile.root = null; profile.rootId = null; profile.rootDnaId = null; profile.rootShortName = null; profile.child1 = null; profile.child1Id = null; profile.child1DnaId = null; profile.child1ShortName = null; profile.child2 = null; profile.child2Id = null; profile.child2DnaId = null; profile.child2ShortName = null; profile.child3 = null; profile.child3Id = null; profile.child3DnaId = null; profile.child3ShortName = null; profile.child4 = null; profile.child4Id = null; profile.child4DnaId = null; profile.child4ShortName = null; profile.orgRevisionId = null; profile.posMasterNo = null; profile.positionName = null; profile.positionField = null; profile.posTypeId = null; profile.posTypeName = null; profile.posLevelId = null; profile.posLevelName = null; // profile.PositionLevel = null; // profile.PositionType = null; // profile.Amount = null; // profile.MouthSalaryAmount = null; // profile.PositionSalaryAmount = null; profile.RecruitDate = null; profile.ReportingDate = null; profile.node = null; profile.nodeId = null; profile.posmasterId = null; profile.positionId = null; profile.Draft = null; profile.typeCommand = null; profile.PlacementStatus = "UN-CONTAIN"; _context.SaveChanges(); return Success(); } [HttpPut("date/update/{personalId:length(36)}")] public async Task> UpdateDateDraft([FromBody] PersonDateRequest req, Guid personalId) { var getPermission = await _permission.GetPermissionAPIAsync("UPDATE", "SYS_PLACEMENT_PASS"); var jsonData = JsonConvert.DeserializeObject(getPermission); if (jsonData["status"]?.ToString() != "200") { return Error(jsonData["message"]?.ToString(), StatusCodes.Status403Forbidden); } var profile = await _context.PlacementProfiles .FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); profile.ReportingDate = req.Date; _context.SaveChanges(); return Success(); } [HttpGet("user/{personalId:length(36)}")] public async Task> GetUserByOrganization(Guid personalId) { var profile = await _context.Profiles .FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); var organization = await _context.Organizations .Include(x => x.Parent) .FirstOrDefaultAsync(x => x.Id == profile.OcId); if (organization == null) return Error(GlobalMessages.OrganizationNotFound, 404); var profilePosition = await _context.ProfilePositions .Where(x => x.Profile != null) .Where(x => x.OrganizationPosition != null) .Where(x => x.OrganizationPosition.PositionMaster != null) .Where(x => x.Profile != profile) .Where(x => x.OrganizationPosition.Organization == organization) .Select(x => new { Id = x.Profile.Id, Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, FirstName = x.Profile.FirstName, LastName = x.Profile.LastName, CitizenId = x.Profile.CitizenId, Position = x.OrganizationPosition.PositionMaster.PositionPath == null ? "-" : x.OrganizationPosition.PositionMaster.PositionPath.Name, PositionLevel = x.Profile.PositionLevel == null ? "-" : x.Profile.PositionLevel.Name, IsDirector = x.OrganizationPosition.PositionMaster.IsDirector, }) .ToListAsync(); var caregiver = profilePosition.Where(x => x.IsDirector == false).ToList(); var commander = profilePosition.Where(x => x.IsDirector == true).ToList(); if (organization.Parent != null) { var profilePositionHigh = await _context.ProfilePositions .Where(x => x.Profile != null) .Where(x => x.OrganizationPosition != null) .Where(x => x.OrganizationPosition.PositionMaster != null) .Where(x => x.Profile != profile) .Where(x => x.OrganizationPosition.Organization == organization.Parent) .Select(x => new { Id = x.Profile.Id, Prefix = x.Profile.Prefix == null ? null : x.Profile.Prefix.Name, FirstName = x.Profile.FirstName, LastName = x.Profile.LastName, CitizenId = x.Profile.CitizenId, Position = x.Profile.Position == null ? "-" : x.Profile.Position.Name, PositionLevel = x.Profile.PositionLevel == null ? "-" : x.Profile.PositionLevel.Name, IsDirector = x.OrganizationPosition.PositionMaster.IsDirector, }) .ToListAsync(); var chairman = profilePositionHigh.Where(x => x.IsDirector == true).ToList(); return Success(new { caregiver, commander, chairman }); } return Success(new { caregiver, commander, chairman = new List() }); } [HttpGet("file/{docId:length(36)}")] public async Task> GetPathFile(Guid docId) { if (docId == Guid.Parse("00000000-0000-0000-0000-000000000000")) return Error(GlobalMessages.DataNotFound, 404); var path = await _documentService.ImagesPath(docId); return Success(path); } [HttpPut("doc/{personalId:length(36)}")] public async Task> UpdateDoc([FromForm] PlacementFileRequest req, Guid personalId) { var placementProfile = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .FirstOrDefaultAsync(x => x.Id == personalId); if (placementProfile == null) return Error(GlobalMessages.DataNotFound, 404); if (Request.Form.Files != null && Request.Form.Files.Count != 0) { foreach (var file in Request.Form.Files) { var fileExtension = Path.GetExtension(file.FileName); var doc = await _documentService.UploadFileAsync(file, file.FileName); var _doc = await _context.Documents.AsQueryable() .FirstOrDefaultAsync(x => x.Id == doc.Id); if (_doc != null) { var placementProfileDoc = new PlacementProfileDoc { PlacementProfile = placementProfile, Document = _doc, CreatedFullName = FullName ?? "System Administrator", CreatedUserId = UserId ?? "", CreatedAt = DateTime.Now, LastUpdateFullName = FullName ?? "System Administrator", LastUpdateUserId = UserId ?? "", LastUpdatedAt = DateTime.Now, }; await _context.PlacementProfileDocs.AddAsync(placementProfileDoc); } } } _context.SaveChanges(); return Success(); } [HttpDelete("doc/{personalId:length(36)}/{docId:length(36)}")] public async Task> DeleteDoc(Guid personalId, Guid docId) { var person = await _context.PlacementProfiles .Include(x => x.PlacementProfileDocs) .ThenInclude(x => x.Document) .FirstOrDefaultAsync(x => x.Id == personalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); var profileDoc = person.PlacementProfileDocs.FirstOrDefault(x => x.Document.Id == docId); if (profileDoc == null) return Error(GlobalMessages.FileNotFoundOnServer, 404); _context.PlacementProfileDocs.RemoveRange(profileDoc); var _docId = profileDoc.Document.Id; await _context.SaveChangesAsync(); await _documentService.DeleteFileAsync(_docId); await _context.SaveChangesAsync(); return Success(); } /// /// หน่วยงานที่ถูกเลือกไปแล้ว /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("use")] public async Task> GetPositionUse() { var position = await _context.PlacementProfiles .Where(x => x.posmasterId != null) .Where(x => x.PlacementStatus != "DONE" && x.PlacementStatus != "REPORT") .Select(x => x.posmasterId) .ToListAsync(); return Success(position); } /// /// ส่งรายชื่อออกคำสั่ง C-PM-01 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("recruit/report")] public async Task> PostReportRecruit([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles // .Include(x => x.Placement) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINT") .ToListAsync(); placementProfiles.ForEach(profile => { profile.PlacementStatus = req.status.Trim().ToUpper(); profile.typeCommand = "APPOINT"; }); await _context.SaveChangesAsync(); return Success(); } /// /// ลบรายชื่อออกคำสั่ง C-PM-01 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("recruit/report/delete")] public async Task> PostReportDeleteRecruit([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); await _context.SaveChangesAsync(); return Success(); } /// /// เอกสารแนบท้าย C-PM-01 /// /// Record Id ของคำสั่ง /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("recruit/report/attachment")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostReportRecruitAttachment([FromBody] ReportAttachmentRequest req) { try { var report_data = (from p in _context.PlacementProfiles .Include(x => x.Placement) .Include(x => x.PlacementEducations) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINT") .ToList() join r in req.refIds on p.Id.ToString() equals r.refId orderby r.Sequence select new { No = r.Sequence.ToString().ToThaiNumber(), FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : $"{p.PlacementEducations.FirstOrDefault().Degree} {p.PlacementEducations.FirstOrDefault().Field}", PositionName = p.positionName == null ? "-" : p.positionName, ExamNumber = p.ExamNumber == null ? "-" : p.ExamNumber.Value.ToString().ToThaiNumber(), PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()} {p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}", Oc = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.PositionExecutive == null ? "" : (p.positionExecutiveField == null ? $"{p.PositionExecutive}\n" : $"{p.PositionExecutive}({p.positionExecutiveField})\n")) + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), PositionType = p.posTypeName == null ? "-" : p.posTypeName, PositionLevel = p.posLevelName == null ? "-" : p.posLevelName, PositionNumber = p.posMasterNo == null ? "-" : p.node == 4 ? $"{p.child4ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 3 ? $"{p.child3ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 2 ? $"{p.child2ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 1 ? $"{p.child1ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 0 ? $"{p.rootShortName} {p.posMasterNo}".ToThaiNumber() : "-", Salary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber().ToThaiNumber(), AppointDate = p.ReportingDate == null ? "-" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(), OccupationPosition = p.OccupationPosition == null ? "-" : p.OccupationPosition, //ตำแหน่งเก่าก่อนสอบ PositionCandidate = p.PositionCandidate, //ตำแหน่งที่สอบแข่งขัน OcCandidate = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() }).ToList(); var result = new List(); foreach (var r in report_data) { result.Add(r); string? _null = null; if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") { result.Add(new { No = _null, FullName = r.RemarkHorizontal, Education = _null, PositionName = _null, ExamNumber = _null, PlacementName = _null, Oc = _null, PositionType = _null, PositionLevel = _null, PositionNumber = _null, Salary = _null, AppointDate = _null, CommandExcecuteDate = _null, OccupationPosition = _null, PositionCandidate = _null, OcCandidate = _null, RemarkHorizontal = _null, RemarkVertical = _null, }); } } return Success(result); } catch { throw; } } /// /// ออกคำสั่ง C-PM-01 บรรจุและแต่งตั้งผู้สอบแข่งขันได้ /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("recruit/report/excecute")] public async Task> PostReportExecuteRecruit([FromBody] ReportExecuteRequest req) { try { var placementProfile = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .Include(x => x.PlacementEducations) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); if (placementProfile == null) return NotFound(); var resultData = (from p in placementProfile join r in req.refIds on p.Id.ToString() equals r.refId select new { bodyProfile = new { rank = string.Empty, prefix = p.Prefix == null ? string.Empty : p.Prefix, firstName = p.Firstname == null ? string.Empty : p.Firstname, lastName = p.Lastname == null ? string.Empty : p.Lastname, citizenId = p.CitizenId == null ? string.Empty : p.CitizenId, position = p.positionName == null ? string.Empty : p.positionName, posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, email = p.Email == null ? string.Empty : p.Email, phone = p.MobilePhone == null ? string.Empty : Regex.Replace(p.MobilePhone, @"\D", ""), keycloak = string.Empty, isProbation = true, isLeave = false, dateRetire = (DateTime?)null, dateAppoint = r.commandDateAffect, dateStart = r.commandDateAffect, govAgeAbsent = 0, govAgePlus = 0, birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth, reasonSameDate = (DateTime?)null, ethnicity = p.Race == null ? string.Empty : p.Race, telephoneNumber = p.Telephone == null ? string.Empty : Regex.Replace(p.Telephone, @"\D", ""), nationality = p.Nationality == null ? string.Empty : p.Nationality, gender = p.Gender == null ? string.Empty : p.Gender, relationship = p.Relationship == null ? string.Empty : p.Relationship, religion = p.Religion == null ? string.Empty : p.Religion, bloodGroup = string.Empty, registrationAddress = string.IsNullOrWhiteSpace(p.RegistAddress) ? string.Empty : p.RegistAddress, registrationProvinceId = p.RegistProvinceId ?? null, registrationDistrictId = p.RegistDistrictId ?? null, registrationSubDistrictId = p.RegistSubDistrictId ?? null, registrationZipCode = p.RegistZipCode == null ? null : p.RegistZipCode, currentAddress = string.IsNullOrWhiteSpace(p.CurrentAddress) ? string.Empty : p.CurrentAddress, currentProvinceId = p.CurrentProvinceId ?? null, currentDistrictId = p.CurrentDistrictId ?? null, currentSubDistrictId = p.CurrentSubDistrictId ?? null, currentZipCode = p.CurrentZipCode == null ? null : p.CurrentZipCode, amount = r.amount, amountSpecial = r.amountSpecial, }, bodyEducations = p.PlacementEducations.Select(e => new { profileId = string.Empty, country = e.Country ?? string.Empty, degree = e.Degree ?? string.Empty, duration = e.Duration ?? string.Empty, durationYear = e.DurationYear ?? null, field = e.Field ?? string.Empty, finishDate = (e.FinishDate == null || e.FinishDate == DateTime.MinValue) ? (DateTime?)null : e.FinishDate, fundName = e.FundName ?? string.Empty, gpa = e.Gpa ?? string.Empty, institute = e.Institute ?? string.Empty, other = e.Other ?? string.Empty, startDate = (e.StartDate == null || e.StartDate == DateTime.MinValue) ? (DateTime?)null : e.StartDate, endDate = (e.EndDate == null || e.EndDate == DateTime.MinValue) ? (DateTime?)null : e.EndDate, educationLevel = e.EducationLevelName, educationLevelId = e.EducationLevelId, positionPath = e.PositionPath?.Name ?? string.Empty, positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty, isDate = e.IsDate ?? false, isEducation = e.IsEducation ?? false, note = e.Other ?? string.Empty }).ToList(), bodyCertificates = p.PlacementCertificates.Select(e => new { profileId = string.Empty, expireDate = (e.ExpireDate == null || e.ExpireDate == DateTime.MinValue) ? (DateTime?)null : e.ExpireDate, issueDate = (e.IssueDate == null || e.IssueDate == DateTime.MinValue) ? (DateTime?)null : e.IssueDate, certificateNo = e.CertificateNo ?? string.Empty, certificateType = e.CertificateType ?? string.Empty, issuer = e.Issuer ?? string.Empty }).ToList(), bodySalarys = new { profileId = p.profileId, amount = r.amount, amountSpecial = r.amountSpecial, positionSalaryAmount = r.positionSalaryAmount, mouthSalaryAmount = r.mouthSalaryAmount, positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, positionType = p.posTypeName, positionLevel = p.posLevelName, commandId = r.commandId, orgRoot = p.root, orgChild1 = p.child1, orgChild2 = p.child2, orgChild3 = p.child3, orgChild4 = p.child4, commandNo = r.commandNo, commandYear = r.commandYear, posNo = p.posMasterNo?.ToString(), posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : p.node == 3 ? $"{p.child3ShortName}" : p.node == 2 ? $"{p.child2ShortName}" : p.node == 1 ? $"{p.child1ShortName}" : p.node == 0 ? $"{p.rootShortName}" : "", commandDateAffect = r.commandDateAffect, commandDateSign = r.commandDateSign, positionName = p.positionName, commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, }, bodyPosition = new { posmasterId = p.posmasterId, positionId = p.positionId }, bodyMarry = new { marry = p.Marry, marryPrefix = p.MarryPrefix, marryFirstName = p.MarryFirstName, marryLastName = p.MarryLastName, marryOccupation = p.MarryOccupation, marryNationality = p.MarryNationality, }, bodyFather = new { fatherPrefix = p.FatherPrefix, fatherFirstName = p.FatherFirstName, fatherLastName = p.FatherLastName, fatherOccupation = p.FatherOccupation, fatherNationality = p.FatherNationality, }, bodyMother = new { motherPrefix = p.MotherPrefix, motherFirstName = p.MotherFirstName, motherLastName = p.MotherLastName, motherOccupation = p.MotherOccupation, motherNationality = p.MotherNationality, }, }).ToList(); var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); var _res = await client.PostAsJsonAsync(apiUrl, new { data = resultData }); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; profile.refCommandCode = req.refIds[0].commandCode; profile.refCommandDate = req.refIds[0].commandDateAffect; profile.refCommandName = req.refIds[0].commandName; profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; profile.templateDoc = req.refIds[0].remark; } }); await _context.SaveChangesAsync(); } } return Success(); } catch { throw; } } /// /// ส่งรายชื่อออกคำสั่ง C-PM-02 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("candidate/report")] public async Task> PostReportCandidate([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles // .Include(x => x.Placement) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name != "สอบคัดเลือก") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINT") .ToListAsync(); placementProfiles.ForEach(profile => { profile.PlacementStatus = req.status.Trim().ToUpper(); profile.typeCommand = "APPOINT"; }); await _context.SaveChangesAsync(); return Success(); } /// /// ลบรายชื่อออกคำสั่ง C-PM-02 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("candidate/report/delete")] public async Task> PostReportDeleteCandidate([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAI"); await _context.SaveChangesAsync(); return Success(); } /// /// เอกสารแนบท้าย C-PM-02 /// /// Record Id ของคำสั่ง /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("candidate/report/attachment")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostReportCandidateAttachment([FromBody] ReportAttachmentRequest req) { try { var report_data = (from p in _context.PlacementProfiles .Include(x => x.Placement) .Include(x => x.PlacementEducations) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name != "สอบแข่งขัน") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOINT") .ToList() join r in req.refIds on p.Id.ToString() equals r.refId orderby r.Sequence select new { No = r.Sequence.ToString().ToThaiNumber(), FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : $"{p.PlacementEducations.FirstOrDefault().Degree} {p.PlacementEducations.FirstOrDefault().Field}", PositionName = p.positionName == null ? "-" : p.positionName, ExamNumber = p.ExamNumber == null ? "-" : p.ExamNumber.Value.ToString().ToThaiNumber(), PlacementName = $"{p.Placement.Name.ToThaiNumber()} ครั้งที่ {p.Placement.Round.ToThaiNumber()} {p.Placement.Year.ToThaiYear().ToString().ToThaiNumber()}", Oc = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.PositionExecutive == null ? "" : (p.positionExecutiveField == null ? $"{p.PositionExecutive}\n" : $"{p.PositionExecutive}({p.positionExecutiveField})\n")) + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), PositionType = p.posTypeName == null ? "-" : p.posTypeName, PositionLevel = p.posLevelName == null ? "-" : p.posLevelName, PositionNumber = p.posMasterNo == null ? "-" : p.node == 4 ? $"{p.child4ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 3 ? $"{p.child3ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 2 ? $"{p.child2ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 1 ? $"{p.child1ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 0 ? $"{p.rootShortName} {p.posMasterNo}".ToThaiNumber() : "-", Salary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber().ToThaiNumber(), AppointDate = p.ReportingDate == null ? "-" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(), PositionCandidate = p.PositionCandidate, RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() }).ToList(); var result = new List(); foreach (var r in report_data) { result.Add(r); string? _null = null; if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") { result.Add(new { No = _null, FullName = r.RemarkHorizontal, Education = _null, PositionName = _null, ExamNumber = _null, PlacementName = _null, Oc = _null, PositionType = _null, PositionLevel = _null, PositionNumber = _null, Salary = _null, AppointDate = _null, CommandExcecuteDate = _null, OccupationPosition = _null, PositionCandidate = _null, RemarkHorizontal = _null, RemarkVertical = _null, }); } } return Success(result); } catch { throw; } } /// /// ออกคำสั่ง C-PM-02 บรรจุและแต่งตั้งผู้ได้รับคัดเลือก /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("candidate/report/excecute")] public async Task> PostReportExecuteCandidate([FromBody] ReportExecuteRequest req) { try { var placementProfile = await _context.PlacementProfiles .Include(x => x.PlacementCertificates) .Include(x => x.PlacementEducations) .Include(x => x.ProfileImg) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); if (placementProfile == null) return NotFound(); var resultData = (from p in placementProfile join r in req.refIds on p.Id.ToString() equals r.refId select new { bodyProfile = new { rank = string.Empty, prefix = p.Prefix == null ? string.Empty : p.Prefix, firstName = p.Firstname == null ? string.Empty : p.Firstname, lastName = p.Lastname == null ? string.Empty : p.Lastname, citizenId = p.CitizenId == null ? string.Empty : p.CitizenId, position = p.positionName == null ? string.Empty : p.positionName, posLevelId = p.posLevelId == null ? string.Empty : p.posLevelId, posTypeId = p.posTypeId == null ? string.Empty : p.posTypeId, email = p.Email == null ? string.Empty : p.Email, phone = p.Telephone == null ? string.Empty : p.Telephone, keycloak = string.Empty, isProbation = true, isLeave = false, dateRetire = (DateTime?)null, dateAppoint = r.commandDateAffect, dateStart = r.commandDateAffect, govAgeAbsent = 0, govAgePlus = 0, birthDate = (p.DateOfBirth == null || p.DateOfBirth == DateTime.MinValue) ? (DateTime?)null : p.DateOfBirth, reasonSameDate = (DateTime?)null, ethnicity = p.Race == null ? string.Empty : p.Race, telephoneNumber = p.Telephone == null ? string.Empty : p.Telephone, nationality = p.Nationality == null ? string.Empty : p.Nationality, gender = p.Gender == null ? string.Empty : p.Gender, relationship = p.Relationship == null ? string.Empty : p.Relationship, religion = p.Religion == null ? string.Empty : p.Religion, bloodGroup = p.BloodGroup, registrationAddress = string.IsNullOrWhiteSpace(p.RegistAddress) ? string.Empty : p.RegistAddress, registrationProvinceId = p.RegistProvinceId ?? null, registrationDistrictId = p.RegistDistrictId ?? null, registrationSubDistrictId = p.RegistSubDistrictId ?? null, registrationZipCode = p.RegistZipCode == null ? null : p.RegistZipCode, currentAddress = p.RegistSame == true ? (string.IsNullOrWhiteSpace(p.RegistAddress) ? string.Empty : p.RegistAddress) : (string.IsNullOrWhiteSpace(p.CurrentAddress) ? string.Empty : p.CurrentAddress), currentProvinceId = p.RegistSame == true ? p.RegistProvinceId : p.CurrentProvinceId, currentDistrictId = p.RegistSame == true ? p.RegistDistrictId : p.CurrentDistrictId, currentSubDistrictId = p.RegistSame == true ? p.RegistSubDistrictId : p.CurrentSubDistrictId, currentZipCode = p.RegistSame == true ? p.RegistZipCode == null ? null : p.RegistZipCode : p.CurrentZipCode == null ? null : p.CurrentZipCode, amount = r.amount, amountSpecial = r.amountSpecial, objectRefId = p.ProfileImg != null && p.ProfileImg?.ObjectRefId != null ? p.ProfileImg?.ObjectRefId.ToString("D") : null, }, bodyEducations = p.PlacementEducations.Select(e => new { profileId = string.Empty, country = e.Country ?? string.Empty, degree = e.Degree ?? string.Empty, duration = e.Duration ?? string.Empty, durationYear = e.DurationYear ?? null, field = e.Field ?? string.Empty, finishDate = e.FinishDate ?? null, fundName = e.FundName ?? string.Empty, gpa = e.Gpa ?? string.Empty, institute = e.Institute ?? string.Empty, other = e.Other ?? string.Empty, startDate = e.StartDate ?? null, endDate = e.EndDate ?? null, educationLevel = e.EducationLevelName, educationLevelId = e.EducationLevelId, positionPath = e.PositionPath?.Name ?? string.Empty, positionPathId = e.PositionPath?.Id.ToString() ?? string.Empty, isDate = e.IsDate ?? false, isEducation = e.IsEducation ?? false, note = e.Other ?? string.Empty }).ToList(), bodyCertificates = p.PlacementCertificates.Select(e => new { profileId = string.Empty, expireDate = e.ExpireDate ?? null, issueDate = e.IssueDate ?? null, certificateNo = e.CertificateNo ?? string.Empty, certificateType = e.CertificateType ?? string.Empty, issuer = e.Issuer ?? string.Empty }).ToList(), bodySalarys = new { profileId = p.profileId, amount = r.amount, amountSpecial = r.amountSpecial, positionSalaryAmount = r.positionSalaryAmount, mouthSalaryAmount = r.mouthSalaryAmount, positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, positionType = p.posTypeName, positionLevel = p.posLevelName, commandId = r.commandId, orgRoot = p.root, orgChild1 = p.child1, orgChild2 = p.child2, orgChild3 = p.child3, orgChild4 = p.child4, commandNo = r.commandNo, commandYear = r.commandYear, posNo = p.posMasterNo?.ToString(), posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : p.node == 3 ? $"{p.child3ShortName}" : p.node == 2 ? $"{p.child2ShortName}" : p.node == 1 ? $"{p.child1ShortName}" : p.node == 0 ? $"{p.rootShortName}" : "", commandDateAffect = r.commandDateAffect, commandDateSign = r.commandDateSign, positionName = p.positionName, commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, }, bodyPosition = new { posmasterId = p.posmasterId, positionId = p.positionId }, bodyMarry = new { marry = p.Marry, marryPrefix = p.MarryPrefix, marryFirstName = p.MarryFirstName, marryLastName = p.MarryLastName, marryOccupation = p.MarryOccupation, marryNationality = p.MarryNationality, }, bodyFather = new { fatherPrefix = p.FatherPrefix, fatherFirstName = p.FatherFirstName, fatherLastName = p.FatherLastName, fatherOccupation = p.FatherOccupation, fatherNationality = p.FatherNationality, }, bodyMother = new { motherPrefix = p.MotherPrefix, motherFirstName = p.MotherFirstName, motherLastName = p.MotherLastName, motherOccupation = p.MotherOccupation, motherNationality = p.MotherNationality, }, }).ToList(); var apiUrl = $"{_configuration["API"]}/org/command/excexute/create-officer-profile"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); var _res = await client.PostAsJsonAsync(apiUrl, new { data = resultData }); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { placementProfile.ForEach(profile => { profile.PlacementStatus = "DONE"; if (req.refIds.Length > 0) { profile.commandId = req.refIds[0].commandId; profile.refCommandCode = req.refIds[0].commandCode; profile.refCommandDate = req.refIds[0].commandDateAffect; profile.refCommandName = req.refIds[0].commandName; profile.refCommandNo = $"{req.refIds[0].commandNo}/{req.refIds[0].commandYear.ToThaiYear()}"; profile.templateDoc = req.refIds[0].remark; } }); await _context.SaveChangesAsync(); } } // // update placementstatus // placementProfile.ForEach(profile => profile.PlacementStatus = "DONE"); // await _context.SaveChangesAsync(); return Success(); } catch { throw; } } /// /// ส่งรายชื่อออกคำสั่ง C-PM-03 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("appoint/report")] public async Task> PostReportAppoint([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles // .Include(x => x.Placement) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = req.status.Trim().ToUpper()); placementProfiles.ForEach(profile => { profile.PlacementStatus = req.status.Trim().ToUpper(); profile.typeCommand = "APPOIN"; }); await _context.SaveChangesAsync(); return Success(); } /// /// ลบรายชื่อออกคำสั่ง C-PM-03 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("appoint/report/delete")] public async Task> PostReportDeleteAppoint([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); await _context.SaveChangesAsync(); return Success(); } /// /// เอกสารแนบท้าย C-PM-03 /// /// Record Id ของคำสั่ง /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("appoint/report/attachment")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostReportAppointAttachment([FromBody] ReportAttachmentRequest req) { try { var report_data = (from p in _context.PlacementProfiles .Include(x => x.PlacementEducations) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") .ToList() join r in req.refIds on p.Id.ToString() equals r.refId orderby r.Sequence select new { No = r.Sequence.ToString().ToThaiNumber(), FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", // Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : // p.PlacementEducations.FirstOrDefault().Degree, Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : $"{p.PlacementEducations.FirstOrDefault().Degree} {p.PlacementEducations.FirstOrDefault().Field}", OldOc = (p.positionNameOld == null ? "" : $"{p.positionNameOld}\n") + (p.PositionExecutiveOld == null ? "" : (p.positionExecutiveFieldOld == null ? $"{p.PositionExecutiveOld}\n" : $"{p.PositionExecutiveOld}({p.positionExecutiveFieldOld})\n")) + (p.child4Old == null ? "" : $"{p.child4Old}\n") + (p.child3Old == null ? "" : $"{p.child3Old}\n") + (p.child2Old == null ? "" : $"{p.child2Old}\n") + (p.child1Old == null ? "" : $"{p.child1Old}\n") + (p.rootOld == null ? "" : $"{p.rootOld}"), OldPositionType = p.posTypeNameOld == null ? "-" : p.posTypeNameOld, OldPositionLevel = p.posLevelNameOld == null ? "-" : p.posLevelNameOld, OldPositionNumber = p.posMasterNoOld == null ? "-" : p.nodeOld == "4" ? $"{p.child4ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "3" ? $"{p.child3ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "2" ? $"{p.child2ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "1" ? $"{p.child1ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "0" ? $"{p.rootShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : "-", OldSalary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), OldPosition = p.positionNameOld == null ? "-" : p.positionNameOld, NewOc = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.PositionExecutive == null ? "" : (p.positionExecutiveField == null ? $"{p.PositionExecutive}\n" : $"{p.PositionExecutive}({p.positionExecutiveField})\n")) + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), NewPosition = p.positionName == null ? "-" : p.positionName, NewPositionType = p.posTypeName == null ? "-" : p.posTypeName, NewPositionLevel = p.posLevelName == null ? "-" : p.posLevelName, NewPositionNumber = p.posMasterNo == null ? "-" : p.node == 4 ? $"{p.child4ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 3 ? $"{p.child3ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 2 ? $"{p.child2ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 1 ? $"{p.child1ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 0 ? $"{p.rootShortName} {p.posMasterNo}".ToThaiNumber() : "-", NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), AppointDate = p.ReportingDate == null ? "-" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(), RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() }).ToList(); var result = new List(); foreach (var r in report_data) { result.Add(r); string? _null = null; if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") { result.Add(new { No = _null, FullName = r.RemarkHorizontal, Education = _null, OldOc = _null, OldPositionType = _null, OldPositionLevel = _null, OldPositionNumber = _null, OldSalary = _null, OldPosition = _null, NewOc = _null, NewPosition = _null, NewPositionType = _null, NewPositionLevel = _null, NewPositionNumber = _null, NewSalary = _null, AppointDate = _null, CommandExcecuteDate = _null, RemarkHorizontal = _null, RemarkVertical = _null, }); } } return Success(result); } catch { throw; } } /// /// ออกคำสั่ง C-PM-03 แต่งตั้งข้าราชการ /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("appoint/report/excecute")] public async Task> PostReportExecuteAppoint([FromBody] ReportExecuteRequest req) { var data = await _context.PlacementProfiles .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId select new { profileId = p.profileId, amount = r.amount, amountSpecial = r.amountSpecial, positionSalaryAmount = r.positionSalaryAmount, mouthSalaryAmount = r.mouthSalaryAmount, positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, positionType = p.posTypeName, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, commandId = r.commandId, orgRoot = p.root, orgChild1 = p.child1, orgChild2 = p.child2, orgChild3 = p.child3, orgChild4 = p.child4, commandNo = r.commandNo, commandYear = r.commandYear, posNo = p.posMasterNo?.ToString(), posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : p.node == 3 ? $"{p.child3ShortName}" : p.node == 2 ? $"{p.child2ShortName}" : p.node == 1 ? $"{p.child1ShortName}" : p.node == 0 ? $"{p.rootShortName}" : "", commandDateAffect = r.commandDateAffect, commandDateSign = r.commandDateSign, positionName = p.positionName, commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, }).ToList(); var baseAPIOrg = _configuration["API"]; var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrlOrg, new { data = resultData, }); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { data.ForEach(profile => profile.PlacementStatus = "DONE"); await _context.SaveChangesAsync(); } } return Success(); } /// /// ส่งรายชื่อออกคำสั่ง C-PM-04 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("move/report")] public async Task> PostReportMove([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles // .Include(x => x.Placement) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name == "ย้ายข้าราชการ") // .Where(x => x.typeCommand.Trim().ToUpper() == "MOVE") .ToListAsync(); placementProfiles.ForEach(profile => { profile.PlacementStatus = req.status.Trim().ToUpper(); profile.typeCommand = "MOVE"; }); await _context.SaveChangesAsync(); return Success(); } /// /// ลบรายชื่อออกคำสั่ง C-PM-04 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("move/report/delete")] public async Task> PostReportDeleteMove([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.PlacementStatus.ToUpper() == "REPORT") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = "PREPARE-CONTAIN"); await _context.SaveChangesAsync(); return Success(); } /// /// เอกสารแนบท้าย C-PM-04 /// /// Record Id ของคำสั่ง /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("move/report/attachment")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostReportMoveAttachment([FromBody] ReportAttachmentRequest req) { try { var report_data = (from p in _context.PlacementProfiles .Include(x => x.PlacementEducations) // .ThenInclude(x => x.PlacementType) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) // .Where(x => x.Placement!.PlacementType!.Name == "แต่งตั้งข้าราชการ") // .Where(x => x.typeCommand.Trim().ToUpper() == "APPOIN") .ToList() join r in req.refIds on p.Id.ToString() equals r.refId orderby r.Sequence select new { No = r.Sequence.ToString().ToThaiNumber(), FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", // Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : // p.PlacementEducations.FirstOrDefault().Degree, Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : $"{p.PlacementEducations.FirstOrDefault().Degree} {p.PlacementEducations.FirstOrDefault().Field}", OldOc = (p.positionNameOld == null ? "" : $"{p.positionNameOld}\n") + (p.PositionExecutiveOld == null ? "" : (p.positionExecutiveFieldOld == null ? $"{p.PositionExecutiveOld}\n" : $"{p.PositionExecutiveOld}({p.positionExecutiveFieldOld})\n")) + (p.child4Old == null ? "" : $"{p.child4Old}\n") + (p.child3Old == null ? "" : $"{p.child3Old}\n") + (p.child2Old == null ? "" : $"{p.child2Old}\n") + (p.child1Old == null ? "" : $"{p.child1Old}\n") + (p.rootOld == null ? "" : $"{p.rootOld}"), OldPosition = p.positionNameOld == null ? "-" : p.positionNameOld, OldPositionType = p.posTypeNameOld == null ? "-" : p.posTypeNameOld, OldPositionLevel = p.posLevelNameOld == null ? "-" : p.posLevelNameOld, OldPositionNumber = p.posMasterNoOld == null ? "-" : p.nodeOld == "4" ? $"{p.child4ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "3" ? $"{p.child3ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "2" ? $"{p.child2ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "1" ? $"{p.child1ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "0" ? $"{p.rootShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : "-", OldSalary = p.AmountOld == null ? "-" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(), NewOc = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.PositionExecutive == null ? "" : (p.positionExecutiveField == null ? $"{p.PositionExecutive}\n" : $"{p.PositionExecutive}({p.positionExecutiveField})\n")) + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), NewPosition = p.positionName == null ? "-" : p.positionName, NewPositionType = p.posTypeName == null ? "-" : p.posTypeName, NewPositionLevel = p.posLevelName == null ? "-" : p.posLevelName, NewPositionNumber = p.posMasterNo == null ? "-" : p.node == 4 ? $"{p.child4ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 3 ? $"{p.child3ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 2 ? $"{p.child2ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 1 ? $"{p.child1ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 0 ? $"{p.rootShortName} {p.posMasterNo}".ToThaiNumber() : "-", NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), AppointDate = p.ReportingDate == null ? "-" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), CommandExcecuteDate = string.IsNullOrEmpty(r.CommandExcecuteDate.ToString()) ? "-" : r.CommandExcecuteDate.Value.ToThaiShortDate2().ToThaiNumber(), RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() }).ToList(); var result = new List(); foreach (var r in report_data) { result.Add(r); string? _null = null; if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") { result.Add(new { No = _null, FullName = r.RemarkHorizontal, Education = _null, OldOc = _null, OldPosition = _null, OldPositionType = _null, OldPositionLevel = _null, OldPositionNumber = _null, OldSalary = _null, NewOc = _null, NewPosition = _null, NewPositionType = _null, NewPositionLevel = _null, NewPositionNumber = _null, NewSalary = _null, AppointDate = _null, CommandExcecuteDate = _null, RemarkHorizontal = _null, RemarkVertical = _null, }); } } return Success(result); } catch { throw; } } /// /// ออกคำสั่ง C-PM-04 ย้ายข้าราชการ /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("move/report/excecute")] public async Task> PostReportExecuteMove([FromBody] ReportExecuteRequest req) { var data = await _context.PlacementProfiles .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId select new { profileId = p.profileId, amount = r.amount, amountSpecial = r.amountSpecial, positionSalaryAmount = r.positionSalaryAmount, mouthSalaryAmount = r.mouthSalaryAmount, positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, positionType = p.posTypeName, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, commandId = r.commandId, orgRoot = p.root, orgChild1 = p.child1, orgChild2 = p.child2, orgChild3 = p.child3, orgChild4 = p.child4, commandNo = r.commandNo, commandYear = r.commandYear, posNo = p.posMasterNo?.ToString(), posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : p.node == 3 ? $"{p.child3ShortName}" : p.node == 2 ? $"{p.child2ShortName}" : p.node == 1 ? $"{p.child1ShortName}" : p.node == 0 ? $"{p.rootShortName}" : "", commandDateAffect = r.commandDateAffect, commandDateSign = r.commandDateSign, positionName = p.positionName, commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, }).ToList(); var baseAPIOrg = _configuration["API"]; var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrlOrg, new { data = resultData, }); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { data.ForEach(profile => profile.PlacementStatus = "DONE"); await _context.SaveChangesAsync(); } } return Success(); } /// /// ส่งรายชื่อออกคำสั่ง C-PM-06 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("slip/report")] public async Task> PostReportSlip([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = req.status.Trim().ToUpper()); await _context.SaveChangesAsync(); return Success(); } /// /// ลบรายชื่อออกคำสั่ง C-PM-06 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("slip/report/delete")] public async Task> PostReportDeleteSlip([FromBody] ReportPersonRequest req) { var placementProfiles = await _context.PlacementProfiles .Where(x => req.refIds.Contains(x.Id.ToString())) // .Where(x => x.Status.ToUpper() == "REPORT") .ToListAsync(); placementProfiles.ForEach(profile => profile.PlacementStatus = "PENDING"); await _context.SaveChangesAsync(); return Success(); } /// /// เอกสารแนบท้าย C-PM-06 /// /// Record Id ของคำสั่ง /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("slip/report/attachment")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status500InternalServerError)] public async Task> PostReporSlipAttachment([FromBody] ReportAttachmentRequest req) { try { var report_data = (from p in _context.PlacementProfiles .Include(x => x.PlacementEducations) .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToList() join r in req.refIds on p.Id.ToString() equals r.refId orderby r.Sequence select new { No = r.Sequence.ToString().ToThaiNumber(), FullName = $"{r.Prefix}{r.FirstName} {r.LastName}", // Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : // p.PlacementEducations.FirstOrDefault().Degree, Education = p.PlacementEducations == null || p.PlacementEducations.Count == 0 ? "-" : $"{p.PlacementEducations.FirstOrDefault().Degree} {p.PlacementEducations.FirstOrDefault().Field}", OldOc = (p.positionNameOld == null ? "" : $"{p.positionNameOld}\n") + (p.PositionExecutiveOld == null ? "" : (p.positionExecutiveFieldOld == null ? $"{p.PositionExecutiveOld}\n" : $"{p.PositionExecutiveOld}({p.positionExecutiveFieldOld})\n")) + (p.child4Old == null ? "" : $"{p.child4Old}\n") + (p.child3Old == null ? "" : $"{p.child3Old}\n") + (p.child2Old == null ? "" : $"{p.child2Old}\n") + (p.child1Old == null ? "" : $"{p.child1Old}\n") + (p.rootOld == null ? "" : $"{p.rootOld}"), OldPositionType = p.posTypeNameOld == null ? "-" : p.posTypeNameOld, OldPositionLevel = p.posLevelNameOld == null ? "-" : p.posLevelNameOld, OldPositionNumber = p.posMasterNoOld == null ? "-" : p.nodeOld == "4" ? $"{p.child4ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "3" ? $"{p.child3ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "2" ? $"{p.child2ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "1" ? $"{p.child1ShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : p.nodeOld == "0" ? $"{p.rootShortNameOld} {p.posMasterNoOld}".ToThaiNumber() : "-", OldSalary = p.Amount == null ? "-" : p.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), LeaveDate = "-", NewOc = (p.positionName == null ? "" : $"{p.positionName}\n") + (p.PositionExecutive == null ? "" : (p.positionExecutiveField == null ? $"{p.PositionExecutive}\n" : $"{p.PositionExecutive}({p.positionExecutiveField})\n")) + (p.child4 == null ? "" : $"{p.child4}\n") + (p.child3 == null ? "" : $"{p.child3}\n") + (p.child2 == null ? "" : $"{p.child2}\n") + (p.child1 == null ? "" : $"{p.child1}\n") + (p.root == null ? "" : $"{p.root}"), NewPositionType = p.posTypeName == null ? "-" : p.posTypeName, NewPositionLevel = p.posLevelName == null ? "-" : p.posLevelName, NewPositionNumber = p.posMasterNo == null ? "-" : p.node == 4 ? $"{p.child4ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 3 ? $"{p.child3ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 2 ? $"{p.child2ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 1 ? $"{p.child1ShortName} {p.posMasterNo}".ToThaiNumber() : p.node == 0 ? $"{p.rootShortName} {p.posMasterNo}".ToThaiNumber() : "-", NewSalary = r.Amount == null ? "-" : r.Amount.Value.ToNumericNoDecimalText().ToThaiNumber(), AppointDate = p.ReportingDate == null ? "-" : p.ReportingDate.Value.ToThaiShortDate2().ToThaiNumber(), RemarkHorizontal = r.RemarkHorizontal == null ? "-" : r.RemarkHorizontal.ToThaiNumber(), RemarkVertical = r.RemarkVertical == null ? "-" : r.RemarkVertical.ToThaiNumber() }).ToList(); var result = new List(); foreach (var r in report_data) { result.Add(r); string? _null = null; if (r.RemarkHorizontal != null && r.RemarkHorizontal != "") { result.Add(new { No = _null, FullName = r.RemarkHorizontal, Education = _null, OldOc = _null, OldPositionType = _null, OldPositionLevel = _null, OldPositionNumber = _null, OldSalary = _null, LeaveDate = _null, NewOc = _null, NewPositionType = _null, NewPositionLevel = _null, NewPositionNumber = _null, NewSalary = _null, AppointDate = _null, RemarkHorizontal = _null, RemarkVertical = _null, }); } } return Success(result); } catch { throw; } } /// /// ออกคำสั่ง C-PM-06 เลื่อนข้าราชการ /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPost("slip/report/excecute")] public async Task> PostReportExecuteSlip([FromBody] ReportExecuteRequest req) { var data = await _context.PlacementProfiles .Where(x => req.refIds.Select(x => x.refId).Contains(x.Id.ToString())) .ToListAsync(); var resultData = (from p in data join r in req.refIds on p.Id.ToString() equals r.refId select new { profileId = p.profileId, amount = r.amount, amountSpecial = r.amountSpecial, positionSalaryAmount = r.positionSalaryAmount, mouthSalaryAmount = r.mouthSalaryAmount, positionExecutive = p.PositionExecutive, positionExecutiveField = p.positionExecutiveField, positionArea = p.positionArea, positionType = p.posTypeName, positionLevel = p.posLevelName, posmasterId = p.posmasterId, positionId = p.positionId, commandId = r.commandId, orgRoot = p.root, orgChild1 = p.child1, orgChild2 = p.child2, orgChild3 = p.child3, orgChild4 = p.child4, commandNo = r.commandNo, commandYear = r.commandYear, posNo = p.posMasterNo?.ToString(), posNoAbb = p.node == 4 ? $"{p.child4ShortName}" : p.node == 3 ? $"{p.child3ShortName}" : p.node == 2 ? $"{p.child2ShortName}" : p.node == 1 ? $"{p.child1ShortName}" : p.node == 0 ? $"{p.rootShortName}" : "", commandDateAffect = r.commandDateAffect, commandDateSign = r.commandDateSign, positionName = p.positionName, commandCode = r.commandCode, commandName = r.commandName, remark = r.remark, }).ToList(); var baseAPIOrg = _configuration["API"]; var apiUrlOrg = $"{baseAPIOrg}/org/command/excexute/salary-current"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api-key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrlOrg, new { data = resultData, }); var _result = await _res.Content.ReadAsStringAsync(); if (_res.IsSuccessStatusCode) { data.ForEach(profile => profile.PlacementStatus = "DONE"); await _context.SaveChangesAsync(); } } return Success(); } /// /// report1 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("report1")] public async Task> report1(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null) { var apiUrl = $"{_configuration["API"]}/org/find/node-all"; var data = new object(); var data1 = new List(); var data2 = new List(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); var _res = await client.PostAsJsonAsync(apiUrl, new { node, nodeId, }); var _result = await _res.Content.ReadAsStringAsync(); var orgs = JsonConvert.DeserializeObject(_result); if (orgs == null || orgs.result == null) return Error("ไม่พบหน่วยงานนี้ในระบบ", 404); int no = 1; foreach (var item in orgs.result.isRootTrue) { var placementProfiles = _context.PlacementProfiles .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.PlacementStatus.Trim().ToUpper() == "DONE") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var placementAppointments = _context.PlacementAppointments .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE" && x.type.Trim().ToUpper() == "OFFICER") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var pt_count = _context.PlacementTransfers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var pr_count = _context.PlacementReceives .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var po_count = _context.PlacementOfficers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var prp_count = _context.PlacementRepatriations .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var ro_count = _context.RetirementOthers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var pp_appoint = placementProfiles.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pp_slip = placementProfiles.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0; var pp_move = placementProfiles.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0; var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; data1.Add(new { no = no, rootName = item.name, pp_appoint = pp_appoint, pp_slip = pp_slip, pp_move = pp_move, pa_appoint = pa_appoint, pa_slip = pa_slip, pa_move = pa_move, pt_count = pt_count, pr_count = pr_count, po_count = po_count, prp_count = prp_count, ro_count = ro_count, total = (pp_appoint + pp_slip + pp_move + pa_appoint + pa_slip + pa_move + pt_count + pr_count + po_count + prp_count + ro_count) }); no++; } no = 1; foreach (var item in orgs.result.isRootFalse) { var placementProfiles = _context.PlacementProfiles .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.PlacementStatus.Trim().ToUpper() == "DONE") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var placementAppointments = _context.PlacementAppointments .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE" && x.type.Trim().ToUpper() == "OFFICER") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var pt_count = _context.PlacementTransfers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var pr_count = _context.PlacementReceives .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var po_count = _context.PlacementOfficers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var prp_count = _context.PlacementRepatriations .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var ro_count = _context.RetirementOthers .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaOldId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaOldId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaOldId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaOldId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaOldId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE") .Count(); var pp_appoint = placementProfiles.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pp_slip = placementProfiles.FirstOrDefault(x => x.TypeCommand == "APPOIN")?.Count ?? 0; var pp_move = placementProfiles.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0; var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; data2.Add(new { no = no, rootName = item.name, pp_appoint = pp_appoint, pp_slip = pp_slip, pp_move = pp_move, pa_appoint = pa_appoint, pa_slip = pa_slip, pa_move = pa_move, pt_count = pt_count, pr_count = pr_count, po_count = po_count, prp_count = prp_count, ro_count = ro_count, total = (pp_appoint + pp_slip + pp_move + pa_appoint + pa_slip + pa_move + pt_count + pr_count + po_count + prp_count + ro_count) }); no++; } } data = new { template = "reportPlacement01All", reportName = "xlsx-report", data = new { date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}", dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}", data1, data1Count = new { pp_appoint = data1.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint), pp_slip = data1.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip), pp_move = data1.Where(x => x.pp_move > 0).Sum(x => x.pp_move), pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move), pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count), pr_count = data1.Where(x => x.pr_count > 0).Sum(x => x.pr_count), po_count = data1.Where(x => x.po_count > 0).Sum(x => x.po_count), prp_count = data1.Where(x => x.prp_count > 0).Sum(x => x.prp_count), ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count), total = data1.Where(x => x.total > 0).Sum(x => x.total) }, data2, data2Count = new { pp_appoint = data2.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint), pp_slip = data2.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip), pp_move = data2.Where(x => x.pp_move > 0).Sum(x => x.pp_move), pa_appoint = data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move), pt_count = data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count), pr_count = data2.Where(x => x.pr_count > 0).Sum(x => x.pr_count), po_count = data2.Where(x => x.po_count > 0).Sum(x => x.po_count), prp_count = data2.Where(x => x.prp_count > 0).Sum(x => x.prp_count), ro_count = data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count), total = data2.Where(x => x.total > 0).Sum(x => x.total) }, sum = new { pp_appoint = data1.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint) + data2.Where(x => x.pp_appoint > 0).Sum(x => x.pp_appoint), pp_slip = data1.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip) + data2.Where(x => x.pp_slip > 0).Sum(x => x.pp_slip), pp_move = data1.Where(x => x.pp_move > 0).Sum(x => x.pp_move) + data2.Where(x => x.pp_move > 0).Sum(x => x.pp_move), pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint) + data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip) + data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move) + data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move), pt_count = data1.Where(x => x.pt_count > 0).Sum(x => x.pt_count) + data2.Where(x => x.pt_count > 0).Sum(x => x.pt_count), pr_count = data1.Where(x => x.pr_count > 0).Sum(x => x.pr_count) + data2.Where(x => x.pr_count > 0).Sum(x => x.pr_count), po_count = data1.Where(x => x.po_count > 0).Sum(x => x.po_count) + data2.Where(x => x.po_count > 0).Sum(x => x.po_count), prp_count = data1.Where(x => x.prp_count > 0).Sum(x => x.prp_count) + data2.Where(x => x.prp_count > 0).Sum(x => x.prp_count), ro_count = data1.Where(x => x.ro_count > 0).Sum(x => x.ro_count) + data2.Where(x => x.ro_count > 0).Sum(x => x.ro_count), total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total) } } }; return Success(data); } /// /// report2 /// /// /// /// ค่าตัวแปรที่ส่งมาไม่ถูกต้อง /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("report2")] public async Task> report2(string nodeId = "", int? node = null, DateTime? startDate = null, DateTime? endDate = null) { var apiUrl = $"{_configuration["API"]}/org/find/node-all"; var data = new object(); var data1 = new List(); var data2 = new List(); using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl); var _res = await client.PostAsJsonAsync(apiUrl, new { node, nodeId, }); var _result = await _res.Content.ReadAsStringAsync(); var orgs = JsonConvert.DeserializeObject(_result); if (orgs == null || orgs.result == null) return Error("ไม่พบหน่วยงานนี้ในระบบ", 404); int no = 1; foreach (var item in orgs.result.isRootTrue) { var placementAppointments = _context.PlacementAppointments .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE" && x.type.Trim().ToUpper() == "EMPLOYEE") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var pae_count = _context.PlacementAppointmentEmployee .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true)) .Count(); //var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pa_appoint = pae_count; var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0; var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; data1.Add(new { no = no, rootName = item.name, pa_appoint = pa_appoint, pa_slip = pa_slip, pa_move = pa_move, total = (pa_appoint + pa_slip + pa_move) }); no++; } no = 1; foreach (var item in orgs.result.isRootFalse) { var placementAppointments = _context.PlacementAppointments .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true) && x.Status.Trim().ToUpper() == "DONE" && x.type.Trim().ToUpper() == "EMPLOYEE") .GroupBy(x => x.typeCommand.Trim().ToUpper()) .Select(g => new { TypeCommand = g.Key, Count = g.Count() }) .ToList(); var pae_count = _context.PlacementAppointmentEmployee .Where(x => x.CreatedAt.Date >= startDate && x.CreatedAt.Date <= endDate && (node == 0 ? x.rootDnaId.Contains(item.rootDnaId) : true) && (node == 1 ? x.child1DnaId.Contains(item.child1DnaId) : true) && (node == 2 ? x.child2DnaId.Contains(item.child2DnaId) : true) && (node == 3 ? x.child3DnaId.Contains(item.child3DnaId) : true) && (node == 4 ? x.child4DnaId.Contains(item.child4DnaId) : true)) .Count(); //var pa_appoint = placementAppointments.FirstOrDefault(x => x.TypeCommand == "APPOINT")?.Count ?? 0; var pa_appoint = pae_count; var pa_slip = placementAppointments.FirstOrDefault(x => x.TypeCommand == "SLIP")?.Count ?? 0; var pa_move = placementAppointments.FirstOrDefault(x => x.TypeCommand == "MOVE")?.Count ?? 0; data2.Add(new { no = no, rootName = item.name, pa_appoint = pa_appoint, pa_slip = pa_slip, pa_move = pa_move, total = (pa_appoint + pa_slip + pa_move) }); no++; } } data = new { template = "reportPlacement02All", reportName = "xlsx-report", data = new { date = $"ตั้งแต่วันที่ {startDate.Value.Date.ToThaiShortDate().ToThaiNumber()} ถึง {endDate.Value.Date.ToThaiShortDate().ToThaiNumber()}", dateCurrent = $"ณ วันที่ {DateTime.Now.Date.ToThaiShortDate().ToThaiNumber()}", data1, data1Count = new { pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move), total = data1.Where(x => x.total > 0).Sum(x => x.total) }, data2, data2Count = new { pa_appoint = data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move), total = data2.Where(x => x.total > 0).Sum(x => x.total) }, sum = new { pa_appoint = data1.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint) + data2.Where(x => x.pa_appoint > 0).Sum(x => x.pa_appoint), pa_slip = data1.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip) + data2.Where(x => x.pa_slip > 0).Sum(x => x.pa_slip), pa_move = data1.Where(x => x.pa_move > 0).Sum(x => x.pa_move) + data2.Where(x => x.pa_move > 0).Sum(x => x.pa_move), total = data1.Where(x => x.total > 0).Sum(x => x.total) + data2.Where(x => x.total > 0).Sum(x => x.total) } } }; return Success(data); } #region ใบสมัคร /// /// ใบสมัคร /// /// Id ผู้สมัคร /// pdf, docx หรือ xlsx /// /// เมื่อทำการอ่านข้อมูลจาก Relational Database สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpGet("candidate/{exportType}/{Id}")] [AllowAnonymous] public async Task> GetExamCandidate([FromRoute] Guid Id, string exportType = "pdf") { var candidate = await _service.GetExamCandidateAsync(Id); var careers = await _service.GetExamCareerCandidateAsync(Id); var avatar = await _service.GetExamAvatarCandidateAsync(Id); if (candidate != null) { var picContent = avatar == null ? null : await _minIOExamService.ImagesPath(avatar); var mapData = new { Id = candidate.GetType().GetProperty("Id").GetValue(candidate), AvatarId = candidate.GetType().GetProperty("AvatarId").GetValue(candidate), PeriodExamName = candidate.GetType().GetProperty("PeriodExamName").GetValue(candidate), PeriodExamRound = candidate.GetType().GetProperty("PeriodExamRound").GetValue(candidate), PeriodExamYear = candidate.GetType().GetProperty("PeriodExamYear").GetValue(candidate), PositionName = candidate.GetType().GetProperty("PositionName").GetValue(candidate), PositionLevelName = candidate.GetType().GetProperty("PositionLevelName").GetValue(candidate), FullName = candidate.GetType().GetProperty("FullName").GetValue(candidate), Nationality = candidate.GetType().GetProperty("Nationality").GetValue(candidate), Religion = candidate.GetType().GetProperty("Religion").GetValue(candidate), CitizenId = candidate.GetType().GetProperty("CitizenId").GetValue(candidate), DateOfBirth = candidate.GetType().GetProperty("DateOfBirth").GetValue(candidate), Age = candidate.GetType().GetProperty("Age").GetValue(candidate), EducationLevelExamName = candidate.GetType().GetProperty("EducationLevelExamName").GetValue(candidate), EducationName = candidate.GetType().GetProperty("EducationName").GetValue(candidate), EducationMajor = candidate.GetType().GetProperty("EducationMajor").GetValue(candidate), EducationLocation = candidate.GetType().GetProperty("EducationLocation").GetValue(candidate), EducationEndDate = candidate.GetType().GetProperty("EducationEndDate").GetValue(candidate), EducationScores = candidate.GetType().GetProperty("EducationScores").GetValue(candidate), EducationType = candidate.GetType().GetProperty("EducationType").GetValue(candidate), EducationLevelHighName = candidate.GetType().GetProperty("EducationLevelHighName").GetValue(candidate), ExamIdenNumber = candidate.GetType().GetProperty("ExamIdenNumber").GetValue(candidate), OccupationPositionType = candidate.GetType().GetProperty("OccupationPositionType").GetValue(candidate), OccupationPosition = candidate.GetType().GetProperty("OccupationPosition").GetValue(candidate), OccupationSalary = candidate.GetType().GetProperty("OccupationSalary").GetValue(candidate), OccupationGroup = candidate.GetType().GetProperty("OccupationGroup").GetValue(candidate), OccupationPile = candidate.GetType().GetProperty("OccupationPile").GetValue(candidate), OccupationOrg = candidate.GetType().GetProperty("OccupationOrg").GetValue(candidate), OccupationTelephone = candidate.GetType().GetProperty("OccupationTelephone").GetValue(candidate), CareersTotal = candidate.GetType().GetProperty("CareersTotal").GetValue(candidate), RegistAddress = candidate.GetType().GetProperty("RegistAddress").GetValue(candidate), RegistProvinceName = candidate.GetType().GetProperty("RegistProvinceName").GetValue(candidate), RegistDistrictName = candidate.GetType().GetProperty("RegistDistrictName").GetValue(candidate), RegistSubDistrictName = candidate.GetType().GetProperty("RegistSubDistrictName").GetValue(candidate), RegistZipCode = candidate.GetType().GetProperty("RegistZipCode").GetValue(candidate), CurrentAddress = candidate.GetType().GetProperty("CurrentAddress").GetValue(candidate), CurrentProvinceName = candidate.GetType().GetProperty("CurrentProvinceName").GetValue(candidate), CurrentDistrictName = candidate.GetType().GetProperty("CurrentDistrictName").GetValue(candidate), CurrentSubDistrictName = candidate.GetType().GetProperty("CurrentSubDistrictName").GetValue(candidate), CurrentZipCode = candidate.GetType().GetProperty("CurrentZipCode").GetValue(candidate), Telephone = candidate.GetType().GetProperty("Telephone").GetValue(candidate), Email = candidate.GetType().GetProperty("Email").GetValue(candidate), ContactFullName = candidate.GetType().GetProperty("ContactFullName").GetValue(candidate), ContactRelations = candidate.GetType().GetProperty("ContactRelations").GetValue(candidate), ContactTel = candidate.GetType().GetProperty("ContactTel").GetValue(candidate), RegisterDate = candidate.GetType().GetProperty("RegisterDate").GetValue(candidate), Url = picContent ?? "https://bma-ehr.frappet.synology.me/assets/avatar_user-89f22423.jpg", Careers = careers, IsBachelors = candidate.GetType().GetProperty("IsBachelors").GetValue(candidate), EditorConfirms = candidate.GetType().GetProperty("EditorConfirms").GetValue(candidate) }; var data = new { template = "ผลสอบคัดเลือกรายบุคคล", reportName = "docx-report", data = mapData }; return Success(data); } else { return NotFound(); } } #endregion } }