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.MetaData; 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.Security.Cryptography; using Microsoft.Extensions.Configuration; using System.Net.Http.Headers; using Newtonsoft.Json; 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; public PlacementController(PlacementRepository repository, NotificationRepository repositoryNoti, ApplicationDBContext context, MinIOService documentService, IHttpContextAccessor httpContextAccessor, IConfiguration configuration) { _repository = repository; _repositoryNoti = repositoryNoti; _context = context; _documentService = documentService; _httpContextAccessor = httpContextAccessor; _configuration = configuration; } #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? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1"); #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, }).ToList(); return Success(_data); } return Success(data); } [HttpGet("exam/{year}")] public async Task> GetExam(int year) { 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, }).ToListAsync(); return Success(data); } [HttpGet("pass/{examId:length(36)}")] public async Task> GetExamByPlacement(Guid examId) { if (PlacementAdmin == true) { var data = await _context.PlacementProfiles.Where(x => x.Placement.Id == examId).Select(x => new { PersonalId = x.Id, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", IdCard = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, 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, PositionCandidate = x.PositionCandidate == null ? null : x.PositionCandidate.Name, PositionCandidateId = x.PositionCandidate == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionCandidate.Id, ReportingDate = x.ReportingDate, StatusId = x.PlacementStatus, Draft = x.Draft, typeCommand = x.typeCommand, IsOfficer = x.IsOfficer, IsRelief = x.IsRelief, posLevelCandidateId = x.PositionLevel == null ? (Guid?)null : x.PositionLevel.Id, posTypeCandidateId = x.PositionType == null ? (Guid?)null : x.PositionType.Id, }).OrderBy(x => x.ExamNumber).ToListAsync(); var result = new List(); foreach (var p in data) { var _data = new { p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, p.IdCard, p.ExamNumber, p.posmasterId, 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.PositionCandidate, p.PositionCandidateId, p.ReportingDate, BmaOfficer = p.IsOfficer == true ? "OFFICER" : null, p.StatusId, p.Draft, p.typeCommand, p.IsRelief, p.posLevelCandidateId, p.posTypeCandidateId, }; result.Add(_data); } return Success(result); } else { var rootId = ""; var child1Id = ""; var child2Id = ""; var child3Id = ""; var child4Id = ""; var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); var org = JsonConvert.DeserializeObject(_result); if (org == null || org.result == null) return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404); 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; // return Success(new {rootId=rootId,child1Id=child1Id,child2Id=child2Id,child3Id=child3Id,child4Id=child4Id }); var data = await _context.PlacementProfiles .Where(x => x.Placement.Id == examId) .Where(x => x.Draft == true) .Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))) .Select(x => new { PersonalId = x.Id, Avatar = x.ProfileImg == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.ProfileImg.Id, FullName = $"{x.Prefix}{x.Firstname} {x.Lastname}", IdCard = x.CitizenId, ExamNumber = x.ExamNumber, posmasterId = x.posmasterId, 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, PositionCandidate = x.PositionCandidate == null ? null : x.PositionCandidate.Name, PositionCandidateId = x.PositionCandidate == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionCandidate.Id, ReportingDate = x.ReportingDate, StatusId = x.PlacementStatus, Draft = x.Draft, typeCommand = x.typeCommand, IsOfficer = x.IsOfficer, IsRelief = x.IsRelief, posLevelCandidateId = x.PositionLevel == null ? (Guid?)null : x.PositionLevel.Id, posTypeCandidateId = x.PositionType == null ? (Guid?)null : x.PositionType.Id, }).OrderBy(x => x.ExamNumber).ToListAsync(); var result = new List(); foreach (var p in data) { var _data = new { p.PersonalId, Avatar = p.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(p.Avatar), p.FullName, p.IdCard, p.ExamNumber, p.posmasterId, 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.PositionCandidate, p.PositionCandidateId, p.ReportingDate, BmaOfficer = p.IsOfficer == true ? "OFFICER" : null, p.StatusId, p.Draft, p.typeCommand, p.IsRelief, p.posLevelCandidateId, p.posTypeCandidateId, }; result.Add(_data); } return Success(result); } } } [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 == null ? null : x.PositionCandidate.Name, PositionCandidateId = x.PositionCandidate == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : x.PositionCandidate.Id, 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.EducationLevel == null ? null : p.EducationLevel.Name, EducationLevelId = p.EducationLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.EducationLevel.Id, 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.PositionCandidateId, 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) { if (PlacementAdmin == 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(), Contain = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(), Disclaim = x.PlacementProfiles.Where(p => p.PlacementStatus.Trim().ToUpper() == "DISCLAIM").Count(), }).FirstOrDefaultAsync(); if (placement == null) return Error(GlobalMessages.DataNotFound, 404); return Success(placement); } else { var rootId = ""; var child1Id = ""; var child2Id = ""; var child3Id = ""; var child4Id = ""; var apiUrl = $"{_configuration["API"]}/org/profile/keycloak/position"; using (var client = new HttpClient()) { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); var _res = await client.SendAsync(_req); var _result = await _res.Content.ReadAsStringAsync(); var org = JsonConvert.DeserializeObject(_result); if (org == null || org.result == null) return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404); 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; // var profileOrg = await _context.Profiles.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId ?? "00000000-0000-0000-0000-000000000000")); // if (profileOrg == null) // return Error(GlobalMessages.DataNotFound, 404); // var ocIdList = _documentService.GetAllIdByRoot(profileOrg.OcId); var placement = await _context.Placements .Where(x => x.Id == examId) .Select(x => new { Total = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (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 => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (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 => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "PREPARE-CONTAIN").Count(), Contain = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (child2Id == "" ? x.child1Id == child1Id : (child3Id == "" ? x.child2Id == child2Id : (child4Id == "" ? x.child3Id == child3Id : x.child4Id == child4Id))))).Where(p => p.PlacementStatus.Trim().ToUpper() == "CONTAIN").Count(), Disclaim = x.PlacementProfiles.Where(x => x.Draft == true).Where(x => rootId == "" ? true : (child1Id == "" ? x.rootId == rootId : (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); } } } [HttpPost("pass/deferment"), DisableRequestSizeLimit] public async Task> UpdatePersonDeferment([FromForm] PersonDefermentRequest req) { 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 person = await _context.PlacementProfiles .Include(x => x.OrganizationPosition) .Include(x => x.PositionNumber) .Include(x => x.PositionPath) .Include(x => x.PositionLevel) .Include(x => x.PositionLine) .Include(x => x.PositionPathSide) .Include(x => x.PositionType) .FirstOrDefaultAsync(x => x.Id == req.PersonalId); if (person == null) return Error(GlobalMessages.DataNotFound, 404); person.OrganizationPosition = null; person.PositionNumber = null; person.PositionPath = null; person.PositionLevel = null; person.PositionLine = null; person.PositionPathSide = 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; await _context.SaveChangesAsync(); return Success(); } [HttpGet("pass/deferment/{personalId:length(36)}")] public async Task> GetPersonDeferment(Guid personalId) { 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 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("ไม่สามารถแก้ไขข้อมูลนี้ได้เนื่องจากเผยแพร่ไปแล้ว"); // person.organizationName = req.organizationName; // person.orgTreeShortName = req.orgTreeShortName; // person.PosPath = req.posPath; // person.PosNumber = req.posNumber; // person.node = req.node; // person.nodeId = req.nodeId; // person.posmasterId = req.posmasterId; // person.positionId = req.positionId; // person.Amount = req.SalaryAmount; // person.MouthSalaryAmount = req.MouthSalaryAmount; // person.PositionSalaryAmount = req.PositionSalaryAmount; // person.RecruitDate = req.ReportingDate; var apiUrl = $"{_configuration["API"]}/org/find/all"; 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 = 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.rootShortName = org.result.rootShortName; person.child1 = req.node <= 0 ? null : org.result.child1; person.child1Id = req.node <= 0 ? null : org.result.child1Id; 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.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.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.child4ShortName = req.node <= 3 ? null : org.result.child4ShortName; } 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.positionField = req.positionField; person.posTypeId = req.posTypeId; person.posTypeName = req.posTypeName; person.posLevelId = req.posLevelId; person.posLevelName = req.posLevelName; // apiUrl = $"{_configuration["API"]}/org/profile/profileid/position/{person.profileId}"; // using (var client = new HttpClient()) // { // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); // var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl); // var _res = await client.SendAsync(_req); // var _result = await _res.Content.ReadAsStringAsync(); // var org = JsonConvert.DeserializeObject(_result); // if (org == null || org.result == null) // { // person.IsOld = false; // } // else // { // // person.AmountOld = org.result.xxxxxxxx; // person.nodeOld = org.result.node; // person.nodeIdOld = org.result.nodeId; // // person.posmasterIdOld = org.result.xxxxxxxx; // 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.orgRevisionIdOld = org.result.xxxxxxx; // // person.positionIdOld = org.result.xxxxxxx; // person.posMasterNoOld = org.result.posMasterNo; // person.positionNameOld = org.result.position; // // person.positionFieldOld = org.result.xxxxxxx; // 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 educationLevel = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == req.EducationLevelId); if (educationLevel == null && req.EducationLevelId != 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, EducationLevel = educationLevel, 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 educationLevel = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == req.EducationLevelId); if (educationLevel == null && req.EducationLevelId != 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.EducationLevel = educationLevel; 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 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 .Include(x => x.OrganizationPosition) .Include(x => x.PositionNumber) .Include(x => x.PositionPath) .Include(x => x.PositionLevel) .Include(x => x.PositionLine) .Include(x => x.PositionPathSide) .Include(x => x.PositionType) .FirstOrDefaultAsync(x => x.Id == personalId); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); profile.root = null; profile.rootId = null; profile.rootShortName = null; profile.child1 = null; profile.child1Id = null; profile.child1ShortName = null; profile.child2 = null; profile.child2Id = null; profile.child2ShortName = null; profile.child3 = null; profile.child3Id = null; profile.child3ShortName = null; profile.child4 = null; profile.child4Id = 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.OrganizationPosition = null; profile.PositionNumber = null; profile.PositionPath = null; profile.PositionLevel = null; profile.PositionLine = null; profile.PositionPathSide = 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; _context.SaveChanges(); return Success(); } [HttpPut("date/update/{personalId:length(36)}")] public async Task> UpdateDateDraft([FromBody] PersonDateRequest req, Guid personalId) { 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 != "CONTAIN") .Select(x => x.posmasterId) .ToListAsync(); return Success(position); } } }