สมัครสอบตามตำแหน่ง
This commit is contained in:
parent
bed23f911a
commit
43898213b2
25 changed files with 9062 additions and 307 deletions
|
|
@ -78,7 +78,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -148,7 +148,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -216,7 +216,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -288,7 +288,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -337,7 +337,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -369,7 +369,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -402,7 +402,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -442,7 +442,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -475,7 +475,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -506,7 +506,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -523,7 +523,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
{
|
||||
Consend = candidate != null,
|
||||
Status = candidate == null ? null : candidate.Status,
|
||||
PositionExam = candidatePosition?.PositionExam
|
||||
PositionExam = candidatePosition?.PositionExam,
|
||||
Position = candidatePosition == null ? false : true
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -538,10 +539,11 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
var _candidate = await _context.Candidates.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
|
||||
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -555,6 +557,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
var candidate = new Candidate
|
||||
{
|
||||
PeriodExam = exam,
|
||||
PositionExam = position,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
|
|
@ -1211,7 +1214,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
|
@ -1229,6 +1232,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
public async Task UserCheckCandidateService(string examId, string positionId, string status)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (exam == null)
|
||||
|
|
@ -1240,11 +1244,17 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
var position = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId));
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam);
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
||||
var candidateDelete = await _context.Candidates.AsQueryable()
|
||||
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam != position)
|
||||
.ToListAsync();
|
||||
|
||||
_context.Candidates.RemoveRange(candidateDelete);
|
||||
|
||||
candidate = await _context.Candidates.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
|
||||
}
|
||||
|
|
@ -1269,6 +1279,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate.PeriodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.Candidate)
|
||||
.FirstOrDefaultAsync(x => x.Id == candidate.PeriodExam.Id);
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
if (status != "rejectDelete")
|
||||
{
|
||||
candidate.Status = status;
|
||||
|
|
@ -1280,6 +1297,11 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
{
|
||||
candidate.Status = "checkSeat";
|
||||
}
|
||||
if (candidate.Status == "checkSeat")
|
||||
{
|
||||
var num = periodExam.Candidate.Count() + 1;
|
||||
candidate.ExamIdenNumber = "CDC-" + num;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
using System.Security.Claims;
|
||||
using System.Text.Json;
|
||||
using BMA.EHR.Recurit.Exam.Service.Core;
|
||||
using BMA.EHR.Recurit.Exam.Service.Data;
|
||||
using BMA.EHR.Recurit.Exam.Service.Models;
|
||||
using BMA.EHR.Recurit.Exam.Service.Request;
|
||||
using BMA.EHR.Recurit.Exam.Service.Response;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OfficeOpenXml;
|
||||
|
||||
namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||
{
|
||||
|
|
@ -42,13 +45,57 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
{
|
||||
if (showAll)
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
else
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Where(p => p.IsActive)
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.Where(p => p.IsActive)
|
||||
.OrderBy(d => d.Name)
|
||||
.Select(x => new PeriodExam
|
||||
{
|
||||
AnnouncementEndDate = x.AnnouncementEndDate,
|
||||
AnnouncementStartDate = x.AnnouncementStartDate,
|
||||
CheckDisability = x.CheckDisability,
|
||||
CheckDocument = x.CheckDocument,
|
||||
Detail = x.Detail,
|
||||
Fee = x.Fee,
|
||||
Id = x.Id,
|
||||
IsActive = x.IsActive,
|
||||
Name = x.Name,
|
||||
Note = x.Note,
|
||||
OrganizationCodeId = x.OrganizationCodeId,
|
||||
OrganizationCodeName = x.OrganizationCodeName,
|
||||
OrganizationId = x.OrganizationId,
|
||||
OrganizationName = x.OrganizationName,
|
||||
PaymentEndDate = x.PaymentEndDate,
|
||||
PaymentKrungThai = x.PaymentKrungThai,
|
||||
PaymentStartDate = x.PaymentStartDate,
|
||||
RegisterEndDate = x.RegisterEndDate,
|
||||
RegisterStartDate = x.RegisterStartDate,
|
||||
Round = x.Round,
|
||||
SetSeat = x.SetSeat,
|
||||
Year = x.Year,
|
||||
BankExam = x.BankExam.OrderBy(o => o.CreatedAt).Select(b => new BankExam
|
||||
{
|
||||
Id = b.Id,
|
||||
AccountName = b.AccountName,
|
||||
AccountNumber = b.AccountNumber,
|
||||
BankName = b.BankName,
|
||||
}).ToList(),
|
||||
PositionExam = x.PositionExam.OrderBy(o => o.CreatedAt).Select(b => new PositionExam
|
||||
{
|
||||
Id = b.Id,
|
||||
TypeId = b.TypeId,
|
||||
TypeName = b.TypeName,
|
||||
PositionId = b.PositionId,
|
||||
PositionName = b.PositionName,
|
||||
}).ToList(),
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PeriodExam?> GetsExamAndCandidateAsync(string examId, bool showAll = true)
|
||||
|
|
@ -62,6 +109,49 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
return periodExam;
|
||||
}
|
||||
|
||||
public async Task<RequestStatusExam?> GetsStatusPaymentAsync(string examId, bool showAll = true)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
return new RequestStatusExam
|
||||
{
|
||||
Name = periodExam.Name,
|
||||
Status = DateTime.Now > periodExam.PaymentEndDate,
|
||||
SetSeat = periodExam.SetSeat,
|
||||
};
|
||||
}
|
||||
|
||||
public async Task<RequestPositionName?> GetsNamePositionAsync(string examId, string positionId)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
if (positionId != "00000000-0000-0000-0000-000000000000")
|
||||
{
|
||||
return new RequestPositionName
|
||||
{
|
||||
Name = periodExam.Name,
|
||||
Posiiton = periodExam.PositionExam.FirstOrDefault(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == periodExam),
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
return new RequestPositionName
|
||||
{
|
||||
Name = periodExam.Name,
|
||||
Posiiton = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(RequestPeriodExam inserted)
|
||||
{
|
||||
var periodExam = new PeriodExam
|
||||
|
|
@ -118,6 +208,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
PeriodExam = periodExam,
|
||||
PositionId = position.PositionId,
|
||||
PositionName = position.PositionName,
|
||||
TypeId = position.TypeId,
|
||||
TypeName = position.TypeName,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
|
|
@ -137,6 +228,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
public async Task UpdateAsync(string examId, RequestPeriodExam updated)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.BankExam)
|
||||
.Include(x => x.PositionExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
|
|
@ -161,13 +254,100 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
periodExam.PaymentKrungThai = updated.PaymentKrungThai;
|
||||
periodExam.Detail = updated.Detail;
|
||||
periodExam.Note = updated.Note;
|
||||
periodExam.CreatedAt = DateTime.Now;
|
||||
periodExam.CreatedUserId = UserId ?? "";
|
||||
periodExam.LastUpdatedAt = DateTime.Now;
|
||||
periodExam.LastUpdateUserId = UserId ?? "";
|
||||
periodExam.CreatedFullName = FullName ?? "";
|
||||
periodExam.LastUpdateFullName = FullName ?? "";
|
||||
|
||||
foreach (var bank in periodExam.BankExam)
|
||||
{
|
||||
var bankData = updated.BankExam
|
||||
.FirstOrDefault(x => x.Id == bank.Id);
|
||||
if (bankData != null)
|
||||
{
|
||||
bank.AccountName = bankData.AccountName;
|
||||
bank.AccountNumber = bankData.AccountNumber;
|
||||
bank.BankName = bankData.BankName;
|
||||
bank.LastUpdatedAt = DateTime.Now;
|
||||
bank.LastUpdateUserId = UserId ?? "";
|
||||
bank.LastUpdateFullName = FullName ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
var bankDelete = await _context.BankExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == bank.Id);
|
||||
|
||||
if (bankDelete != null)
|
||||
_context.BankExams.Remove(bankDelete);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var position in periodExam.PositionExam)
|
||||
{
|
||||
var positionData = updated.PositionExam
|
||||
.FirstOrDefault(x => x.Id == position.Id);
|
||||
if (positionData != null)
|
||||
{
|
||||
position.PositionId = positionData.PositionId;
|
||||
position.PositionName = positionData.PositionName;
|
||||
position.TypeId = positionData.TypeId;
|
||||
position.TypeName = positionData.TypeName;
|
||||
position.LastUpdatedAt = DateTime.Now;
|
||||
position.LastUpdateUserId = UserId ?? "";
|
||||
position.LastUpdateFullName = FullName ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
var positionDelete = await _context.PositionExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == position.Id);
|
||||
|
||||
if (positionDelete != null)
|
||||
_context.PositionExams.Remove(positionDelete);
|
||||
}
|
||||
}
|
||||
|
||||
var bankAdd = updated.BankExam
|
||||
.Where(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
.ToList();
|
||||
foreach (var bank in bankAdd)
|
||||
{
|
||||
var bankExam = new BankExam
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
AccountName = bank.AccountName,
|
||||
AccountNumber = bank.AccountNumber,
|
||||
BankName = bank.BankName,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
CreatedFullName = FullName ?? "",
|
||||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
await _context.BankExams.AddAsync(bankExam);
|
||||
}
|
||||
|
||||
var positionAdd = updated.PositionExam
|
||||
.Where(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
.ToList();
|
||||
foreach (var position in positionAdd)
|
||||
{
|
||||
var positionExam = new PositionExam
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
PositionId = position.PositionId,
|
||||
PositionName = position.PositionName,
|
||||
TypeId = position.TypeId,
|
||||
TypeName = position.TypeName,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
CreatedFullName = FullName ?? "",
|
||||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
await _context.PositionExams.AddAsync(positionExam);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
|
@ -322,7 +502,171 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<List<RequestImportSeat>> ReadExcelCandidate(IFormFile formFile)
|
||||
{
|
||||
var list = new List<RequestImportSeat>();
|
||||
using (var stream = new MemoryStream())
|
||||
{
|
||||
await formFile.CopyToAsync(stream);
|
||||
using (var package = new ExcelPackage(stream))
|
||||
{
|
||||
for (int i = 0; i < package.Workbook.Worksheets.Count(); i++)
|
||||
{
|
||||
ExcelWorksheet worksheet = package.Workbook.Worksheets[i];
|
||||
var rowCount = worksheet.Dimension.Rows;
|
||||
for (int row = 2; row <= rowCount; row++)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(worksheet);
|
||||
if (worksheet.Cells[row, 1].Value != null)
|
||||
{
|
||||
list.Add(new RequestImportSeat
|
||||
{
|
||||
CitizenId = worksheet.Cells[row, 1].Value != null ? worksheet.Cells[row, 1].Value.ToString() : "-",
|
||||
ExamIdenNumber = worksheet.Cells[row, 2].Value != null ? worksheet.Cells[row, 2].Value.ToString() : "-",
|
||||
SeatNumber = worksheet.Cells[row, 3].Value != null ? worksheet.Cells[row, 3].Value.ToString() : "-",
|
||||
Point = worksheet.Cells[row, 4].Value != null ? worksheet.Cells[row, 4].Value.ToString() : "-",
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task UploadSeatCandidateAsync(string examId, IFormFile excels)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var candidates = await _context.Candidates
|
||||
.AsQueryable()
|
||||
.Where(x => x.PeriodExam == periodExam)
|
||||
.ToListAsync();
|
||||
|
||||
var items = await ReadExcelCandidate(excels);
|
||||
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
var item = items.FirstOrDefault(x => x.CitizenId == candidate.CitizenId && x.ExamIdenNumber == candidate.ExamIdenNumber);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
if (candidate.Status == "checkSeat")
|
||||
{
|
||||
candidate.SeatNumber = item.SeatNumber;
|
||||
candidate.Status = "checkPoint";
|
||||
}
|
||||
else
|
||||
{
|
||||
candidate.Status = "waiver";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
candidate.Status = "waiver";
|
||||
}
|
||||
periodExam.SetSeat = true;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UploadPointCandidateAsync(string examId, IFormFile excels)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var candidates = await _context.Candidates
|
||||
.AsQueryable()
|
||||
.Where(x => x.PeriodExam == periodExam)
|
||||
.ToListAsync();
|
||||
|
||||
var items = await ReadExcelCandidate(excels);
|
||||
|
||||
foreach (var candidate in candidates)
|
||||
{
|
||||
var item = items.FirstOrDefault(x => x.CitizenId == candidate.CitizenId && x.ExamIdenNumber == candidate.ExamIdenNumber);
|
||||
|
||||
if (item != null)
|
||||
{
|
||||
if (candidate.Status == "checkPoint")
|
||||
{
|
||||
candidate.Point = item.Point;
|
||||
candidate.Status = "done";
|
||||
}
|
||||
else
|
||||
{
|
||||
candidate.Status = "waiver";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
candidate.Status = "waiver";
|
||||
}
|
||||
periodExam.SetSeat = true;
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<MemoryStream> DownloadCandidateAsync(string examId)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var candidates = await _context.Candidates
|
||||
.AsQueryable()
|
||||
.Where(x => x.PeriodExam == periodExam)
|
||||
.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 = "คะแนน";
|
||||
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.Point;
|
||||
row++;
|
||||
}
|
||||
summarySheet.Cells[summarySheet.Dimension.Address].AutoFitColumns();
|
||||
package.Save();
|
||||
}
|
||||
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BankExam?>> GetsPaymentExamAsync(string examId)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.BankExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
return periodExam.BankExam;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue