เพิ่มวัหมดอายุเลขบัตร
This commit is contained in:
parent
a781c375d7
commit
7018791857
9 changed files with 638 additions and 285 deletions
|
|
@ -50,11 +50,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
.Select(x => new CandidateInformationResponseItem
|
||||
{
|
||||
Prefix = x.Prefix,
|
||||
PrefixId = x.Prefix != null ? x.Prefix.Id.ToString() : null,
|
||||
FirstName = x.FirstName,
|
||||
LastName = x.LastName,
|
||||
Nationality = x.Nationality,
|
||||
DateOfBirth = x.DateOfBirth,
|
||||
Relationship = x.Relationship,
|
||||
RelationshipId = x.Relationship != null ? x.Relationship.Id.ToString() : null,
|
||||
CitizenProvince = x.CitizenProvince,
|
||||
CitizenProvinceId = x.CitizenProvince != null ? x.CitizenProvince.Id.ToString() : null,
|
||||
CitizenDistrict = x.CitizenDistrict,
|
||||
CitizenDistrictId = x.CitizenDistrict != null ? x.CitizenDistrict.Id.ToString() : null,
|
||||
CitizenDate = x.CitizenDate,
|
||||
Email = x.Email,
|
||||
CitizenId = x.CitizenId,
|
||||
})
|
||||
|
|
@ -75,14 +82,20 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
{
|
||||
RegistAddress = x.RegistAddress,
|
||||
RegistProvince = x.RegistProvince,
|
||||
RegistProvinceId = x.RegistProvince != null ? x.RegistProvince.Id.ToString() : null,
|
||||
RegistDistrict = x.RegistDistrict,
|
||||
RegistDistrictId = x.RegistDistrict != null ? x.RegistDistrict.Id.ToString() : null,
|
||||
RegistSubDistrict = x.RegistSubDistrict,
|
||||
RegistSubDistrictId = x.RegistSubDistrict != null ? x.RegistSubDistrict.Id.ToString() : null,
|
||||
RegistZipCode = x.RegistZipCode,
|
||||
RegistSame = x.RegistSame,
|
||||
CurrentAddress = x.CurrentAddress,
|
||||
CurrentProvince = x.CurrentProvince,
|
||||
CurrentProvinceId = x.CurrentProvince != null ? x.CurrentProvince.Id.ToString() : null,
|
||||
CurrentDistrict = x.CurrentDistrict,
|
||||
CurrentDistrictId = x.CurrentDistrict != null ? x.CurrentDistrict.Id.ToString() : null,
|
||||
CurrentSubDistrict = x.CurrentSubDistrict,
|
||||
CurrentSubDistrictId = x.CurrentSubDistrict != null ? x.CurrentSubDistrict.Id.ToString() : null,
|
||||
CurrentZipCode = x.CurrentZipCode,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
|
@ -102,12 +115,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
{
|
||||
Marry = x.Marry,
|
||||
MarryPrefix = x.MarryPrefix,
|
||||
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
|
||||
MarryFirstName = x.MarryFirstName,
|
||||
MarryLastName = x.MarryLastName,
|
||||
FatherPrefix = x.FatherPrefix,
|
||||
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
|
||||
FatherFirstName = x.FatherFirstName,
|
||||
FatherLastName = x.FatherLastName,
|
||||
MotherPrefix = x.MotherPrefix,
|
||||
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
|
||||
MotherFirstName = x.MotherFirstName,
|
||||
MotherLastName = x.MotherLastName,
|
||||
})
|
||||
|
|
@ -252,12 +268,33 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
candidate.Relationship = relationship;
|
||||
}
|
||||
|
||||
if (updated.CitizenProvinceId != null)
|
||||
{
|
||||
var citizenProvince = await _context.Provinces.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenProvinceId));
|
||||
|
||||
if (citizenProvince == null)
|
||||
throw new Exception(GlobalMessages.ProvinceNotFound);
|
||||
candidate.CitizenProvince = citizenProvince;
|
||||
}
|
||||
|
||||
if (updated.CitizenDistrictId != null)
|
||||
{
|
||||
var citizenDistrict = await _context.Districts.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenDistrictId));
|
||||
|
||||
if (citizenDistrict == null)
|
||||
throw new Exception(GlobalMessages.DistrictNotFound);
|
||||
candidate.CitizenDistrict = citizenDistrict;
|
||||
}
|
||||
|
||||
candidate.FirstName = updated.FirstName;
|
||||
candidate.LastName = updated.LastName;
|
||||
candidate.Nationality = updated.Nationality;
|
||||
candidate.DateOfBirth = updated.DateOfBirth;
|
||||
candidate.Email = updated.Email;
|
||||
candidate.CitizenId = updated.CitizenId;
|
||||
candidate.CitizenDate = updated.CitizenDate;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
|
@ -282,16 +319,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
candidate.RegistProvince = registProvince;
|
||||
}
|
||||
|
||||
if (updated.RegistProvinceId != null)
|
||||
{
|
||||
var registProvince = await _context.Provinces.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistProvinceId));
|
||||
|
||||
if (registProvince == null)
|
||||
throw new Exception(GlobalMessages.ProvinceNotFound);
|
||||
candidate.RegistProvince = registProvince;
|
||||
}
|
||||
|
||||
if (updated.RegistDistrictId != null)
|
||||
{
|
||||
var registDistrict = await _context.Districts.AsQueryable()
|
||||
|
|
@ -323,16 +350,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
candidate.CurrentProvince = currentProvince;
|
||||
}
|
||||
|
||||
if (updated.CurrentProvinceId != null)
|
||||
{
|
||||
var currentProvince = await _context.Provinces.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentProvinceId));
|
||||
|
||||
if (currentProvince == null)
|
||||
throw new Exception(GlobalMessages.ProvinceNotFound);
|
||||
candidate.CurrentProvince = currentProvince;
|
||||
}
|
||||
|
||||
if (updated.CurrentDistrictId != null)
|
||||
{
|
||||
var currentDistrict = await _context.Districts.AsQueryable()
|
||||
|
|
@ -543,7 +560,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task RegisterCandidateService(string examId)
|
||||
public async Task<string> GetStatusCandidateService(string examId)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
|
@ -557,7 +574,37 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
candidate.status = "registered";
|
||||
return candidate.status;
|
||||
}
|
||||
|
||||
public async Task UserCheckCandidateService(string examId, string status)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (exam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var candidate = await _context.Candidates.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
|
||||
|
||||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
candidate.status = status;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task AdminCheckCandidateService(string candidateId, string status)
|
||||
{
|
||||
var candidate = await _context.Candidates.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
||||
|
||||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
candidate.status = status;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
|
|
|||
98
Services/PeriodExamService.cs
Normal file
98
Services/PeriodExamService.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System.Security.Claims;
|
||||
using BMA.EHR.Recurit.Exam.Service.Data;
|
||||
using BMA.EHR.Recurit.Exam.Service.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BMA.EHR.Recurit.Exam.Service.Services
|
||||
{
|
||||
public class PeriodExamService
|
||||
{
|
||||
#region " Fields "
|
||||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public PeriodExamService(ApplicationDbContext context,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_context = context;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<IEnumerable<PeriodExam>> GetsAsync(bool showAll = true)
|
||||
{
|
||||
if (showAll)
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
else
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Where(p => p.IsActive)
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PeriodExam?> GetByIdAsync(Guid id)
|
||||
{
|
||||
return await _context.PeriodExams.FirstOrDefaultAsync(x => x.Id == id);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(Guid id, PeriodExam updated)
|
||||
{
|
||||
var existData = await _context.PeriodExams.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (existData != null)
|
||||
{
|
||||
if (existData.Name != updated.Name)
|
||||
{
|
||||
existData.Name = updated.Name;
|
||||
existData.LastUpdatedAt = DateTime.Now;
|
||||
existData.LastUpdateUserId = UserId ?? "";
|
||||
existData.LastUpdateFullName = FullName ?? "";
|
||||
}
|
||||
|
||||
if (existData.IsActive != updated.IsActive)
|
||||
{
|
||||
existData.IsActive = updated.IsActive;
|
||||
existData.LastUpdatedAt = DateTime.Now;
|
||||
existData.LastUpdateUserId = UserId ?? "";
|
||||
existData.LastUpdateFullName = FullName ?? "";
|
||||
}
|
||||
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(PeriodExam inserted)
|
||||
{
|
||||
inserted.CreatedUserId = UserId ?? "";
|
||||
inserted.CreatedFullName = FullName ?? "System Administrator";
|
||||
inserted.CreatedAt = DateTime.Now;
|
||||
inserted.LastUpdatedAt = DateTime.Now;
|
||||
inserted.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
inserted.LastUpdateUserId = UserId ?? "";
|
||||
|
||||
await _context.PeriodExams.AddAsync(inserted);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue