apiคนพิการ

This commit is contained in:
Kittapath 2023-04-29 10:26:03 +07:00
parent be27aa4d33
commit 1d4043a50e
37 changed files with 9794 additions and 298 deletions

View file

@ -63,6 +63,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<CandidateInformationResponseItem?> GetsAsyncInformation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -133,6 +134,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<CandidateAddressResponseItem?> GetsAsyncAddress(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -201,6 +203,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<CandidateFamilyResponseItem?> GetsAsyncFamily(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -273,6 +276,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<CandidateOccupationResponseItem?> GetsAsyncOccupation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -319,6 +323,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<IEnumerable<Career?>> GetsAsyncCareer(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -351,6 +356,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<IEnumerable<Education?>> GetsAsyncEducation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -383,6 +389,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<IEnumerable<FileListResponse?>> GetsAsyncFileUpload(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -465,6 +472,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<string> GetsAsyncProfileImage(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -516,6 +524,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<PaymentImgResponse> GetsAsyncPaymentImg(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -568,6 +577,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<RequestStatusRegistry> GetsAsyncRegisterExam(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.Include(x => x.BankExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -610,6 +620,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<string> CreateAsyncCandidate(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -1426,6 +1437,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task DeleteAsyncDocument(string examId, string positionId, string documentId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.Include(x => x.PositionExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -1651,6 +1663,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<CandidateStatusResponse> GetStatusCandidateService(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -1680,6 +1693,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UserCheckCandidateService(string examId, string positionId, string status)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.Include(x => x.PositionExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -1856,6 +1870,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<RequestCardCandidate> GetsAsyncCardCandidate(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(p => p.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (exam == null)
@ -1898,6 +1913,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
PointC = candidate.PointC,
ResultC = candidate.ResultC,
Pass = candidate.Pass,
Number = candidate.Number,
AnnouncementDate = exam.AnnouncementDate.AddYears(2),
Id = candidate.Id,
};
@ -1929,6 +1945,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
PointC = candidate.PointC,
ResultC = candidate.ResultC,
Pass = candidate.Pass,
Number = candidate.Number,
AnnouncementDate = candidate.PeriodExam?.AnnouncementDate.AddYears(2),
Id = candidate.Id,
};

View file

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models.Disables;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class DisableService
{
private readonly ApplicationDbContext _context;
public DisableService(ApplicationDbContext context)
{
_context = context;
}
public int GetExamCount(string citizenId)
{
try
{
var count = _context.Disables.AsQueryable()
.Where(x => x.CitizenId == citizenId)
.Count();
return count;
}
catch
{
throw;
}
}
public async Task<string> GetExamAttributeAsync(Guid period, Guid exam)
{
try
{
var payment = await _context.DisablePayments.AsQueryable()
.Include(x => x.Disable)
.ThenInclude(x => x.PeriodExam)
.Where(x => x.Disable.Id == exam)
.Where(x => x.Disable.PeriodExam.Id == period)
.FirstOrDefaultAsync();
return payment != null ? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ";
}
catch
{
throw;
}
}
public bool CheckValidCertificate(DateTime certDate, int nextYear = 5)
{
var valid = true;
if (DateTime.Now.Date > certDate.Date.AddYears(nextYear))
valid = false;
return valid;
}
}
}

View file

@ -1,5 +1,6 @@
using System.Security.Claims;
using System.Text.Json;
using BMA.EHR.Extensions;
using BMA.EHR.Recurit.Exam.Service.Core;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
@ -52,10 +53,42 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
#region " Methods "
private string GenerateStatusCandidate(string status)
{
switch (status.Trim().ToUpper())
{
case "REGISTER": return "รอยืนยันสมัครสอบ";
case "CHECKREGISTER": return "ตรวจสอบข้อมูลสมัครสอบ";
case "PAYMENT": return "รอชำระค่าสมัครสอบ";
case "REJECTREGISTER": return "ปฏิเสธตรวจสอบข้อมูลสมัคร";
case "CHECKPAYMENT": return "ตรวจสอบหลักฐานชำระเงิน";
case "REJECTPAYMENT": return "หลักฐานชำระเงินไม่ถูกต้อง";
case "CHECKSEAT": return "จัดที่นั่งสอบ";
case "CHECKPOINT": return "สรุปคะแนนสอบ";
case "DONE": return "สอบคัดเลือกสำเร็จ";
case "WAIVER": return "สละสิทธิ์สอบ";
default: return status;
}
}
private string GenerateStatusOccupation(string status)
{
switch (status.Trim().ToUpper())
{
case "OFFICIAL": return "ข้าราชการกรุงเทพมหานคร";
case "PERSONNEL": return "บุคลากรกรุงเทพมหานคร";
case "OFFICIALSOTHER": return "ข้าราชการประเภทอื่น";
case "EMPLOYEE": return "ลูกจ้าง/พนักงานราชการของส่วนราชการอื่น";
case "OTHER": return "อื่นๆ";
default: return status;
}
}
public async Task<IEnumerable<PeriodExamCandidateResponseItem>> GetsAsync(string type, bool showAll = true)
{
return await _context.PeriodExams.AsQueryable()
.Where(p => p.IsActive)
.Where(p => p.CheckDisability == false)
.Where(p => type.ToUpper() == "ALL" ? (p.AnnouncementExam == true || p.AnnouncementExam == false) : (type.ToUpper() == "EXAM" ? p.AnnouncementExam == true : p.AnnouncementExam == false))
.OrderByDescending(d => d.CreatedAt)
.Select(x => new PeriodExamCandidateResponseItem
@ -93,6 +126,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<PeriodExamCandidateResponseItem?> GetsExamAndCandidateAsync(string examId, bool showAll = true)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.PositionExam)
.Include(x => x.BankExam)
.Include(x => x.PeriodExamDocuments)
@ -200,6 +234,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<RequestPositionName?> GetsNamePositionAsync(string examId, string positionId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.PositionExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -234,7 +269,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
{
Name = inserted.Name,
CheckDocument = inserted.CheckDocument,
CheckDisability = inserted.CheckDisability,
Round = inserted.Round,
Year = inserted.Year,
Fee = inserted.Fee,
@ -312,6 +346,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UpdateAsync(string examId, RequestPeriodExam updated)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.BankExam)
.Include(x => x.PositionExam)
.Include(x => x.Candidate)
@ -324,7 +359,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
periodExam.Name = updated.Name;
periodExam.CheckDocument = updated.CheckDocument;
periodExam.CheckDisability = updated.CheckDisability;
periodExam.Round = updated.Round;
periodExam.Year = updated.Year;
periodExam.Fee = updated.Fee;
@ -462,6 +496,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UpdateDocAsync(string examId, IFormFileCollection files)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -492,6 +527,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UpdateImgAsync(string examId, IFormFileCollection files)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -527,6 +563,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task DeleteAsyncDocument(string examId, string documentId)
{
var exam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.PositionExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -539,6 +576,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task DeleteAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -551,6 +589,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<IEnumerable<Candidate?>> GetsCandidateByStatusAsync(string examId, string status)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -563,6 +602,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.OrderByDescending(d => d.CreatedAt)
.Where(x => x.PeriodExam == periodExam && x.Status != "register" && x.Status != "rejectRegister")
.ToListAsync();
if (candidate.Where(x => x.Status == "done").FirstOrDefault() != null)
candidate = candidate.OrderBy(x => x.Number).ToList();
var i = 0;
foreach (var item in candidate)
{
@ -579,6 +620,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.OrderByDescending(d => d.CreatedAt)
.Where(x => x.PeriodExam == periodExam && x.Status == status)
.ToListAsync();
if (candidate.Where(x => x.Status == "done").FirstOrDefault() != null)
candidate = candidate.OrderBy(x => x.Number).ToList();
var i = 0;
foreach (var item in candidate)
{
@ -782,16 +825,17 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
{
list.Add(new RequestImportSeat
{
CitizenId = worksheet.Cells[row, 1].Value != null ? worksheet.Cells[row, 1].Value.ToString() : null,
ExamIdenNumber = worksheet.Cells[row, 2].Value != null ? worksheet.Cells[row, 2].Value.ToString() : null,
SeatNumber = worksheet.Cells[row, 3].Value != null ? worksheet.Cells[row, 3].Value.ToString() : null,
PointTotalB = worksheet.Cells[row, 4].Value != null ? worksheet.Cells[row, 4].Value.ToString() : null,
PointB = worksheet.Cells[row, 5].Value != null ? worksheet.Cells[row, 5].Value.ToString() : null,
ResultB = worksheet.Cells[row, 6].Value != null ? worksheet.Cells[row, 6].Value.ToString() : null,
PointTotalC = worksheet.Cells[row, 7].Value != null ? worksheet.Cells[row, 7].Value.ToString() : null,
PointC = worksheet.Cells[row, 8].Value != null ? worksheet.Cells[row, 8].Value.ToString() : null,
ResultC = worksheet.Cells[row, 9].Value != null ? worksheet.Cells[row, 9].Value.ToString() : null,
Pass = worksheet.Cells[row, 10].Value != null ? (worksheet.Cells[row, 10].Value.ToString()) : null,
Number = worksheet.Cells[row, 1].Value != null ? worksheet.Cells[row, 1].Value.ToString() : null,
CitizenId = worksheet.Cells[row, 2].Value != null ? worksheet.Cells[row, 2].Value.ToString() : null,
ExamIdenNumber = worksheet.Cells[row, 3].Value != null ? worksheet.Cells[row, 3].Value.ToString() : null,
SeatNumber = worksheet.Cells[row, 4].Value != null ? worksheet.Cells[row, 4].Value.ToString() : null,
PointTotalB = worksheet.Cells[row, 5].Value != null ? worksheet.Cells[row, 5].Value.ToString() : null,
PointB = worksheet.Cells[row, 6].Value != null ? worksheet.Cells[row, 6].Value.ToString() : null,
ResultB = worksheet.Cells[row, 7].Value != null ? worksheet.Cells[row, 7].Value.ToString() : null,
PointTotalC = worksheet.Cells[row, 8].Value != null ? worksheet.Cells[row, 8].Value.ToString() : null,
PointC = worksheet.Cells[row, 9].Value != null ? worksheet.Cells[row, 9].Value.ToString() : null,
ResultC = worksheet.Cells[row, 10].Value != null ? worksheet.Cells[row, 10].Value.ToString() : null,
Pass = worksheet.Cells[row, 11].Value != null ? (worksheet.Cells[row, 11].Value.ToString()) : null,
});
}
}
@ -804,6 +848,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UploadSeatCandidateAsync(string examId, IFormFile excels)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -859,6 +904,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task UploadPointCandidateAsync(string examId, IFormFile excels)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -886,6 +932,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
candidate.PointC = item.PointC;
candidate.ResultC = item.ResultC;
candidate.Pass = item.Pass;
candidate.Number = item.Number;
var subject = "แจ้งผลการสมัครสอบคัดเลือก " + periodExam.Name;
var body = candidate.FirstName + " " + candidate.LastName + " สถานะการสมัครสอบ: สอบคัดเลือกสำเร็จ";
if (candidate.Email != null) _mailService.SendMailToUser(subject, body, candidate.Email);
@ -920,6 +967,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<MemoryStream> DownloadCandidateAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
@ -951,30 +999,32 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
summarySheet.TabColor = System.Drawing.Color.Black;
// summarySheet.DefaultRowHeight = 17;
summarySheet.Row(1).Style.Font.Bold = true;
summarySheet.Cells[1, 1].Value = "เลขบัตรประชาชน";
summarySheet.Cells[1, 2].Value = "เลขประจำตัวสอบ";
summarySheet.Cells[1, 3].Value = "เลขที่นั่งสอบ";
summarySheet.Cells[1, 4].Value = "คะแนนเต็มภาค ข";
summarySheet.Cells[1, 5].Value = "คะแนนภาค ข";
summarySheet.Cells[1, 6].Value = "ผลสอบภาค ข";
summarySheet.Cells[1, 7].Value = "คะแนนเต็มภาค ค";
summarySheet.Cells[1, 8].Value = "คะแนนภาค ค";
summarySheet.Cells[1, 9].Value = "ผลสอบภาค ค";
summarySheet.Cells[1, 10].Value = "ผลการสอบ";
summarySheet.Cells[1, 1].Value = "ลำดับที่สอบได้";
summarySheet.Cells[1, 2].Value = "เลขบัตรประชาชน";
summarySheet.Cells[1, 3].Value = "เลขประจำตัวสอบ";
summarySheet.Cells[1, 4].Value = "เลขที่นั่งสอบ";
summarySheet.Cells[1, 5].Value = "คะแนนเต็มภาค ข";
summarySheet.Cells[1, 6].Value = "คะแนนภาค ข";
summarySheet.Cells[1, 7].Value = "ผลสอบภาค ข";
summarySheet.Cells[1, 8].Value = "คะแนนเต็มภาค ค";
summarySheet.Cells[1, 9].Value = "คะแนนภาค ค";
summarySheet.Cells[1, 10].Value = "ผลสอบภาค ค";
summarySheet.Cells[1, 11].Value = "ผลการสอบ";
int row = 2;
foreach (var item in candidates)
{
summarySheet.Cells[row, 1].Value = item.CitizenId;
summarySheet.Cells[row, 2].Value = item.ExamIdenNumber;
summarySheet.Cells[row, 3].Value = item.SeatNumber;
summarySheet.Cells[row, 4].Value = item.PointTotalB;
summarySheet.Cells[row, 5].Value = item.PointB;
summarySheet.Cells[row, 6].Value = item.ResultB;
summarySheet.Cells[row, 7].Value = item.PointTotalC;
summarySheet.Cells[row, 8].Value = item.PointC;
summarySheet.Cells[row, 9].Value = item.ResultC;
summarySheet.Cells[row, 10].Value = item.Pass;
summarySheet.Cells[row, 1].Value = item.Number;
summarySheet.Cells[row, 2].Value = item.CitizenId;
summarySheet.Cells[row, 3].Value = item.ExamIdenNumber;
summarySheet.Cells[row, 4].Value = item.SeatNumber;
summarySheet.Cells[row, 5].Value = item.PointTotalB;
summarySheet.Cells[row, 6].Value = item.PointB;
summarySheet.Cells[row, 7].Value = item.ResultB;
summarySheet.Cells[row, 8].Value = item.PointTotalC;
summarySheet.Cells[row, 9].Value = item.PointC;
summarySheet.Cells[row, 10].Value = item.ResultC;
summarySheet.Cells[row, 11].Value = item.Pass;
row++;
}
summarySheet.Cells[summarySheet.Dimension.Address].AutoFitColumns();
@ -988,6 +1038,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<PeriodExam> GetsPaymentExamAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.BankExam)
.Where(x => x.Id == Guid.Parse(examId))
.Select(x => new PeriodExam
@ -1006,6 +1057,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<List<DashboardResponseItem>> GetsDashboardPaymentExamAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.Include(x => x.Candidate)
.ThenInclude(x => x.PaymentImg)
.Where(x => x.Id == Guid.Parse(examId))
@ -1068,6 +1120,389 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return dashboard;
}
public async Task<MemoryStream> DownloadCandidateAllAsync(string examId)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.Where(x => x.CheckDisability == false)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
if (periodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
// var _candidates = (from c in _context.Candidates
// where c.PeriodExam == periodExam
// select new
// {
// Id = c.Id,
// Status = c.Status,
// CitizenId = c.CitizenId,
// FullName = $"{c.PrefixName}{c.FirstName} {c.LastName}",
// Nationality = c.Nationality,
// DateOfBirth = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.ToThaiShortDate(),
// Age = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.CalculateGovAgeStr(0, 0),
// RelationshipName = c.RelationshipName,
// Telephone = c.Telephone,
// MobilePhone = c.MobilePhone,
// Email = c.Email,
// Knowledge = c.Knowledge,
// RegistAddress = c.RegistAddress,
// RegistProvinceName = c.RegistProvinceName,
// RegistDistrictName = c.RegistDistrictName,
// RegistSubDistrictName = c.RegistSubDistrictName,
// RegistZipCode = c.RegistZipCode,
// CurrentAddress = c.CurrentAddress,
// CurrentProvinceName = c.CurrentProvinceName,
// CurrentDistrictName = c.CurrentDistrictName,
// CurrentSubDistrictName = c.CurrentSubDistrictName,
// CurrentZipCode = c.CurrentZipCode,
// MarryFullName = $"{c.MarryPrefixName}{c.MarryFirstName} {c.MarryLastName}",
// FatherFullName = $"{c.FatherPrefixName}{c.FatherFirstName} {c.FatherLastName}",
// MotherFullName = $"{c.MotherPrefixName}{c.MotherFirstName} {c.MotherLastName}",
// OccupationType = c.OccupationType,
// OccupationPosition = c.OccupationPosition,
// OccupationCompany = c.OccupationCompany,
// OccupationDepartment = c.OccupationDepartment,
// OccupationEmail = c.OccupationEmail,
// OccupationTelephone = c.OccupationTelephone,
// Number = c.Number,
// ExamIdenNumber = c.ExamIdenNumber,
// SeatNumber = c.SeatNumber,
// PointTotalB = c.PointTotalB,
// PointB = c.PointB,
// ResultB = c.ResultB,
// PointTotalC = c.PointTotalC,
// PointC = c.PointC,
// ResultC = c.ResultC,
// Pass = c.Pass,
// }
// ).ToList();
var candidates = await _context.Candidates
.AsQueryable()
.OrderBy(x => x.ExamIdenNumber)
.Where(x => x.PeriodExam == periodExam)
.Select(c => new
{
Id = c.Id,
Status = c.Status,
CitizenId = c.CitizenId,
FullName = $"{c.PrefixName}{c.FirstName} {c.LastName}",
Nationality = c.Nationality,
DateOfBirth = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.ToThaiShortDate(),
Age = c.DateOfBirth == null ? "" : c.DateOfBirth.Value.Date.CalculateGovAgeStr(0, 0),
RelationshipName = c.RelationshipName,
Telephone = c.Telephone,
MobilePhone = c.MobilePhone,
Email = c.Email,
Knowledge = c.Knowledge,
RegistAddress = c.RegistAddress,
RegistProvinceName = c.RegistProvinceName,
RegistDistrictName = c.RegistDistrictName,
RegistSubDistrictName = c.RegistSubDistrictName,
RegistZipCode = c.RegistZipCode,
CurrentAddress = c.CurrentAddress,
CurrentProvinceName = c.CurrentProvinceName,
CurrentDistrictName = c.CurrentDistrictName,
CurrentSubDistrictName = c.CurrentSubDistrictName,
CurrentZipCode = c.CurrentZipCode,
MarryFullName = $"{c.MarryPrefixName}{c.MarryFirstName} {c.MarryLastName}",
FatherFullName = $"{c.FatherPrefixName}{c.FatherFirstName} {c.FatherLastName}",
MotherFullName = $"{c.MotherPrefixName}{c.MotherFirstName} {c.MotherLastName}",
OccupationType = c.OccupationType,
OccupationPosition = c.OccupationPosition,
OccupationCompany = c.OccupationCompany,
OccupationDepartment = c.OccupationDepartment,
OccupationEmail = c.OccupationEmail,
OccupationTelephone = c.OccupationTelephone,
Number = c.Number,
ExamIdenNumber = c.ExamIdenNumber,
SeatNumber = c.SeatNumber,
PointTotalB = c.PointTotalB,
PointB = c.PointB,
ResultB = c.ResultB,
PointTotalC = c.PointTotalC,
PointC = c.PointC,
ResultC = c.ResultC,
Pass = c.Pass,
})
.ToListAsync();
var stream = new MemoryStream();
using (var package = new ExcelPackage(stream))
{
var summarySheet = package.Workbook.Worksheets.Add("Candidate");
summarySheet.TabColor = System.Drawing.Color.Black;
// summarySheet.DefaultRowHeight = 17;
summarySheet.Row(1).Style.Font.Bold = true;
summarySheet.Cells[1, 1].Value = "สถานะสอบคัดเลือก";
summarySheet.Cells[1, 2].Value = "เลขบัตรประชาชน";
summarySheet.Cells[1, 3].Value = "ชื่อ-สกุล";
summarySheet.Cells[1, 4].Value = "สัญชาติ";
summarySheet.Cells[1, 5].Value = "วันเกิด";
summarySheet.Cells[1, 6].Value = "อายุ";
summarySheet.Cells[1, 7].Value = "สถานภาพ";
summarySheet.Cells[1, 8].Value = "โทรศัพท์";
summarySheet.Cells[1, 9].Value = "โทรศัพท์มือถือ";
summarySheet.Cells[1, 10].Value = "อีเมล";
summarySheet.Cells[1, 11].Value = "ความรู้ความสามารถพิเศษ";
summarySheet.Cells[1, 12].Value = "ที่อยู่ตามทะเบียนบ้าน";
summarySheet.Cells[1, 13].Value = "จังหวัดที่อยู่ตามทะเบียนบ้าน";
summarySheet.Cells[1, 14].Value = "เขต/อำเภอที่อยู่ตามทะเบียนบ้าน";
summarySheet.Cells[1, 15].Value = "ตำบล/แขวงที่อยู่ตามทะเบียนบ้าน";
summarySheet.Cells[1, 16].Value = "รหัสไปรษณีย์ที่อยู่ตามทะเบียนบ้าน";
summarySheet.Cells[1, 17].Value = "ที่อยู่ปัจจุบัน";
summarySheet.Cells[1, 18].Value = "จังหวัดที่อยู่ปัจจุบัน";
summarySheet.Cells[1, 19].Value = "เขต/อำเภอที่อยู่ปัจจุบัน";
summarySheet.Cells[1, 20].Value = "ตำบล/แขวงที่อยู่ปัจจุบัน";
summarySheet.Cells[1, 21].Value = "รหัสไปรษณีย์ที่อยู่ปัจจุบัน";
summarySheet.Cells[1, 22].Value = "คู่สมรส";
summarySheet.Cells[1, 23].Value = "บิดา";
summarySheet.Cells[1, 24].Value = "มารดา";
summarySheet.Cells[1, 25].Value = "อาชีพ";
summarySheet.Cells[1, 26].Value = "ตำแหน่ง";
summarySheet.Cells[1, 27].Value = "สำนัก/บริษัท";
summarySheet.Cells[1, 28].Value = "กอง/ฝ่าย";
summarySheet.Cells[1, 29].Value = "อีเมลบริษัท";
summarySheet.Cells[1, 30].Value = "โทรศัพท์บริษัท";
summarySheet.Cells[1, 31].Value = "วุฒิที่ได้รับ";
summarySheet.Cells[1, 32].Value = "สาขา/วิชาเอก";
summarySheet.Cells[1, 33].Value = "คะแนนเฉลี่ยตลอดหลักสูตร";
summarySheet.Cells[1, 34].Value = "ชื่อสถานศีกษา";
summarySheet.Cells[1, 35].Value = "ระยะเวลาเริ่มศึกษา";
summarySheet.Cells[1, 36].Value = "ระยะเวลาสิ้นสุดศึกษา";
summarySheet.Cells[1, 37].Value = "สถานที่ทำงาน/ฝึกงาน";
summarySheet.Cells[1, 38].Value = "ตำแหน่ง/ลักษณะงาน";
summarySheet.Cells[1, 39].Value = "เงินเดือนสุดท้านก่อนออก";
summarySheet.Cells[1, 40].Value = "ระยะเวลาเริ่มทำงาน/ฝึกงาน";
summarySheet.Cells[1, 41].Value = "ระยะเวลาสิ้นสุดทำงาน/ฝึกงาน";
summarySheet.Cells[1, 42].Value = "เหตุผลที่ออก";
summarySheet.Cells[1, 43].Value = "ลำดับที่สอบได้";
summarySheet.Cells[1, 44].Value = "เลขประจำตัวสอบ";
summarySheet.Cells[1, 45].Value = "เลขที่นั่งสอบ";
summarySheet.Cells[1, 46].Value = "คะแนนเต็มภาค ข";
summarySheet.Cells[1, 47].Value = "คะแนนภาค ข";
summarySheet.Cells[1, 48].Value = "ผลสอบภาค ข";
summarySheet.Cells[1, 49].Value = "คะแนนเต็มภาค ค";
summarySheet.Cells[1, 50].Value = "คะแนนภาค ค";
summarySheet.Cells[1, 51].Value = "ผลสอบภาค ค";
summarySheet.Cells[1, 52].Value = "ผลการสอบ";
int row = 2;
foreach (var item in candidates)
{
summarySheet.Cells[row, 1].Value = GenerateStatusCandidate(item.Status);
summarySheet.Cells[row, 2].Value = item.CitizenId;
summarySheet.Cells[row, 3].Value = item.FullName;
summarySheet.Cells[row, 4].Value = item.Nationality;
summarySheet.Cells[row, 5].Value = item.DateOfBirth;
summarySheet.Cells[row, 6].Value = item.Age;
summarySheet.Cells[row, 7].Value = item.RelationshipName;
summarySheet.Cells[row, 8].Value = item.Telephone;
summarySheet.Cells[row, 9].Value = item.MobilePhone;
summarySheet.Cells[row, 10].Value = item.Email;
summarySheet.Cells[row, 11].Value = item.Knowledge;
summarySheet.Cells[row, 12].Value = item.RegistAddress;
summarySheet.Cells[row, 13].Value = item.RegistProvinceName;
summarySheet.Cells[row, 14].Value = item.RegistDistrictName;
summarySheet.Cells[row, 15].Value = item.RegistSubDistrictName;
summarySheet.Cells[row, 16].Value = item.RegistZipCode;
summarySheet.Cells[row, 17].Value = item.CurrentAddress;
summarySheet.Cells[row, 18].Value = item.CurrentProvinceName;
summarySheet.Cells[row, 19].Value = item.CurrentDistrictName;
summarySheet.Cells[row, 20].Value = item.CurrentSubDistrictName;
summarySheet.Cells[row, 21].Value = item.CurrentZipCode;
summarySheet.Cells[row, 22].Value = item.MarryFullName;
summarySheet.Cells[row, 23].Value = item.FatherFullName;
summarySheet.Cells[row, 24].Value = item.MotherFullName;
summarySheet.Cells[row, 25].Value = GenerateStatusOccupation(item.OccupationType);
summarySheet.Cells[row, 26].Value = item.OccupationPosition;
summarySheet.Cells[row, 27].Value = item.OccupationCompany;
summarySheet.Cells[row, 28].Value = item.OccupationDepartment;
summarySheet.Cells[row, 29].Value = item.OccupationEmail;
summarySheet.Cells[row, 30].Value = item.OccupationTelephone;
summarySheet.Cells[row, 43].Value = item.Number;
summarySheet.Cells[row, 44].Value = item.ExamIdenNumber;
summarySheet.Cells[row, 45].Value = item.SeatNumber;
summarySheet.Cells[row, 46].Value = item.PointTotalB;
summarySheet.Cells[row, 47].Value = item.PointB;
summarySheet.Cells[row, 48].Value = item.ResultB;
summarySheet.Cells[row, 49].Value = item.PointTotalC;
summarySheet.Cells[row, 50].Value = item.PointC;
summarySheet.Cells[row, 51].Value = item.ResultC;
summarySheet.Cells[row, 52].Value = item.Pass;
row++;
var educations = await _context.Educations
.AsQueryable()
.OrderBy(x => x.DurationStart)
.Where(x => x.Candidate.Id == item.Id)
.ToListAsync();
foreach (var education in educations)
{
summarySheet.Cells[row, 1].Value = GenerateStatusCandidate(item.Status);
summarySheet.Cells[row, 2].Value = item.CitizenId;
summarySheet.Cells[row, 3].Value = item.FullName;
summarySheet.Cells[row, 4].Value = item.Nationality;
summarySheet.Cells[row, 5].Value = item.DateOfBirth;
summarySheet.Cells[row, 6].Value = item.Age;
summarySheet.Cells[row, 7].Value = item.RelationshipName;
summarySheet.Cells[row, 8].Value = item.Telephone;
summarySheet.Cells[row, 9].Value = item.MobilePhone;
summarySheet.Cells[row, 10].Value = item.Email;
summarySheet.Cells[row, 11].Value = item.Knowledge;
summarySheet.Cells[row, 12].Value = item.RegistAddress;
summarySheet.Cells[row, 13].Value = item.RegistProvinceName;
summarySheet.Cells[row, 14].Value = item.RegistDistrictName;
summarySheet.Cells[row, 15].Value = item.RegistSubDistrictName;
summarySheet.Cells[row, 16].Value = item.RegistZipCode;
summarySheet.Cells[row, 17].Value = item.CurrentAddress;
summarySheet.Cells[row, 18].Value = item.CurrentProvinceName;
summarySheet.Cells[row, 19].Value = item.CurrentDistrictName;
summarySheet.Cells[row, 20].Value = item.CurrentSubDistrictName;
summarySheet.Cells[row, 21].Value = item.CurrentZipCode;
summarySheet.Cells[row, 22].Value = item.MarryFullName;
summarySheet.Cells[row, 23].Value = item.FatherFullName;
summarySheet.Cells[row, 24].Value = item.MotherFullName;
summarySheet.Cells[row, 25].Value = GenerateStatusOccupation(item.OccupationType);
summarySheet.Cells[row, 26].Value = item.OccupationPosition;
summarySheet.Cells[row, 27].Value = item.OccupationCompany;
summarySheet.Cells[row, 28].Value = item.OccupationDepartment;
summarySheet.Cells[row, 29].Value = item.OccupationEmail;
summarySheet.Cells[row, 30].Value = item.OccupationTelephone;
summarySheet.Cells[row, 31].Value = education.EducationLevelName;
summarySheet.Cells[row, 32].Value = education.Major;
summarySheet.Cells[row, 33].Value = education.Scores;
summarySheet.Cells[row, 34].Value = education.Name;
summarySheet.Cells[row, 35].Value = education.DurationStart == null ? "" : education.DurationStart.Date.ToThaiShortDate();
summarySheet.Cells[row, 36].Value = education.DurationEnd == null ? "" : education.DurationEnd.Date.ToThaiShortDate();
summarySheet.Cells[row, 43].Value = item.Number;
summarySheet.Cells[row, 44].Value = item.ExamIdenNumber;
summarySheet.Cells[row, 45].Value = item.SeatNumber;
summarySheet.Cells[row, 46].Value = item.PointTotalB;
summarySheet.Cells[row, 47].Value = item.PointB;
summarySheet.Cells[row, 48].Value = item.ResultB;
summarySheet.Cells[row, 49].Value = item.PointTotalC;
summarySheet.Cells[row, 50].Value = item.PointC;
summarySheet.Cells[row, 51].Value = item.ResultC;
summarySheet.Cells[row, 52].Value = item.Pass;
row++;
}
var careers = await _context.Careers
.AsQueryable()
.OrderBy(x => x.DurationStart)
.Where(x => x.Candidate.Id == item.Id)
.ToListAsync();
foreach (var career in careers)
{
summarySheet.Cells[row, 1].Value = GenerateStatusCandidate(item.Status);
summarySheet.Cells[row, 2].Value = item.CitizenId;
summarySheet.Cells[row, 3].Value = item.FullName;
summarySheet.Cells[row, 4].Value = item.Nationality;
summarySheet.Cells[row, 5].Value = item.DateOfBirth;
summarySheet.Cells[row, 6].Value = item.Age;
summarySheet.Cells[row, 7].Value = item.RelationshipName;
summarySheet.Cells[row, 8].Value = item.Telephone;
summarySheet.Cells[row, 9].Value = item.MobilePhone;
summarySheet.Cells[row, 10].Value = item.Email;
summarySheet.Cells[row, 11].Value = item.Knowledge;
summarySheet.Cells[row, 12].Value = item.RegistAddress;
summarySheet.Cells[row, 13].Value = item.RegistProvinceName;
summarySheet.Cells[row, 14].Value = item.RegistDistrictName;
summarySheet.Cells[row, 15].Value = item.RegistSubDistrictName;
summarySheet.Cells[row, 16].Value = item.RegistZipCode;
summarySheet.Cells[row, 17].Value = item.CurrentAddress;
summarySheet.Cells[row, 18].Value = item.CurrentProvinceName;
summarySheet.Cells[row, 19].Value = item.CurrentDistrictName;
summarySheet.Cells[row, 20].Value = item.CurrentSubDistrictName;
summarySheet.Cells[row, 21].Value = item.CurrentZipCode;
summarySheet.Cells[row, 22].Value = item.MarryFullName;
summarySheet.Cells[row, 23].Value = item.FatherFullName;
summarySheet.Cells[row, 24].Value = item.MotherFullName;
summarySheet.Cells[row, 25].Value = GenerateStatusOccupation(item.OccupationType);
summarySheet.Cells[row, 26].Value = item.OccupationPosition;
summarySheet.Cells[row, 27].Value = item.OccupationCompany;
summarySheet.Cells[row, 28].Value = item.OccupationDepartment;
summarySheet.Cells[row, 29].Value = item.OccupationEmail;
summarySheet.Cells[row, 30].Value = item.OccupationTelephone;
summarySheet.Cells[row, 37].Value = career.Name;
summarySheet.Cells[row, 38].Value = career.Position;
summarySheet.Cells[row, 39].Value = career.Salary;
summarySheet.Cells[row, 40].Value = career.DurationStart == null ? "" : career.DurationStart.Date.ToThaiShortDate();
summarySheet.Cells[row, 41].Value = career.DurationEnd == null ? "" : career.DurationEnd.Date.ToThaiShortDate();
summarySheet.Cells[row, 42].Value = career.Reason;
summarySheet.Cells[row, 43].Value = item.Number;
summarySheet.Cells[row, 44].Value = item.ExamIdenNumber;
summarySheet.Cells[row, 45].Value = item.SeatNumber;
summarySheet.Cells[row, 46].Value = item.PointTotalB;
summarySheet.Cells[row, 47].Value = item.PointB;
summarySheet.Cells[row, 48].Value = item.ResultB;
summarySheet.Cells[row, 49].Value = item.PointTotalC;
summarySheet.Cells[row, 50].Value = item.PointC;
summarySheet.Cells[row, 51].Value = item.ResultC;
summarySheet.Cells[row, 52].Value = item.Pass;
row++;
}
}
summarySheet.Cells[summarySheet.Dimension.Address].AutoFitColumns();
package.Save();
}
stream.Position = 0;
return stream;
}
// public async Task<MemoryStream> GetsDashboardExamAsync(string examId)
// {
// var periodExam = await _context.PeriodExams.AsQueryable()
// .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
// if (periodExam == null)
// throw new Exception(GlobalMessages.ExamNotFound);
// var stream = new MemoryStream();
// using (var package = new ExcelPackage(stream))
// {
// var summarySheet = package.Workbook.Worksheets.Add("Dashboard");
// summarySheet.TabColor = System.Drawing.Color.Black;
// // summarySheet.DefaultRowHeight = 17;
// summarySheet.Row(1).Style.Font.Bold = true;
// summarySheet.Cells[1, 1].Value = "จำนวนผู้สมัครคัดเลือกทั้งหมด";
// summarySheet.Cells[1, 2].Value = "จำนวนผู้มีสิทธิ์เข้ารับคัดเลือกทั้งหมด";
// summarySheet.Cells[1, 3].Value = "จำนวนผู้เข้ารับการคัดเลือกทั้งหมด";
// summarySheet.Cells[1, 4].Value = "ผ่านการสอบ";
// summarySheet.Cells[1, 5].Value = "ไม่ผ่านการสอบ";
// summarySheet.Cells[1, 6].Value = "คะแนนภาค ข";
// summarySheet.Cells[1, 7].Value = "ผลสอบภาค ข";
// summarySheet.Cells[1, 8].Value = "คะแนนเต็มภาค ค";
// summarySheet.Cells[1, 9].Value = "คะแนนภาค ค";
// summarySheet.Cells[1, 10].Value = "ผลสอบภาค ค";
// summarySheet.Cells[1, 11].Value = "ผลการสอบ";
// summarySheet.Cells[2, 1].Value = periodExam;
// summarySheet.Cells[2, 2].Value = periodExam;
// summarySheet.Cells[2, 3].Value = periodExam;
// summarySheet.Cells[2, 4].Value = periodExam;
// summarySheet.Cells[2, 5].Value = periodExam;
// summarySheet.Cells[2, 6].Value = periodExam;
// summarySheet.Cells[2, 7].Value = periodExam;
// summarySheet.Cells[2, 8].Value = periodExam;
// summarySheet.Cells[2, 9].Value = periodExam;
// summarySheet.Cells[2, 10].Value = periodExam;
// summarySheet.Cells[2, 11].Value = periodExam;
// summarySheet.Cells[summarySheet.Dimension.Address].AutoFitColumns();
// package.Save();
// }
// stream.Position = 0;
// return stream;
// }
#endregion
}
}