2023-03-23 21:41:26 +07:00
|
|
|
|
using System.Security.Claims;
|
|
|
|
|
|
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.Response;
|
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BMA.EHR.Recurit.Exam.Service.Services
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CandidateService
|
|
|
|
|
|
{
|
|
|
|
|
|
#region " Fields "
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ApplicationDbContext _context;
|
|
|
|
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region " Constructor and Destructor "
|
|
|
|
|
|
|
|
|
|
|
|
public CandidateService(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<CandidateInformationResponseItem?> GetsAsyncInformation(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exam = await _context.PeriodExams.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
|
|
|
|
|
|
|
|
|
|
|
if (exam == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
|
|
|
|
|
|
.Select(x => new CandidateInformationResponseItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Prefix = x.Prefix,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
PrefixId = x.Prefix != null ? x.Prefix.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
FirstName = x.FirstName,
|
|
|
|
|
|
LastName = x.LastName,
|
|
|
|
|
|
Nationality = x.Nationality,
|
|
|
|
|
|
DateOfBirth = x.DateOfBirth,
|
|
|
|
|
|
Relationship = x.Relationship,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
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,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
Email = x.Email,
|
|
|
|
|
|
CitizenId = x.CitizenId,
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<CandidateAddressResponseItem?> GetsAsyncAddress(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exam = await _context.PeriodExams.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
|
|
|
|
|
|
|
|
|
|
|
if (exam == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
|
|
|
|
|
|
.Select(x => new CandidateAddressResponseItem
|
|
|
|
|
|
{
|
|
|
|
|
|
RegistAddress = x.RegistAddress,
|
|
|
|
|
|
RegistProvince = x.RegistProvince,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
RegistProvinceId = x.RegistProvince != null ? x.RegistProvince.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
RegistDistrict = x.RegistDistrict,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
RegistDistrictId = x.RegistDistrict != null ? x.RegistDistrict.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
RegistSubDistrict = x.RegistSubDistrict,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
RegistSubDistrictId = x.RegistSubDistrict != null ? x.RegistSubDistrict.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
RegistZipCode = x.RegistZipCode,
|
|
|
|
|
|
RegistSame = x.RegistSame,
|
|
|
|
|
|
CurrentAddress = x.CurrentAddress,
|
|
|
|
|
|
CurrentProvince = x.CurrentProvince,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
CurrentProvinceId = x.CurrentProvince != null ? x.CurrentProvince.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
CurrentDistrict = x.CurrentDistrict,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
CurrentDistrictId = x.CurrentDistrict != null ? x.CurrentDistrict.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
CurrentSubDistrict = x.CurrentSubDistrict,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
CurrentSubDistrictId = x.CurrentSubDistrict != null ? x.CurrentSubDistrict.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
CurrentZipCode = x.CurrentZipCode,
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<CandidateFamilyResponseItem?> GetsAsyncFamily(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exam = await _context.PeriodExams.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
|
|
|
|
|
|
|
|
|
|
|
if (exam == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
|
|
|
|
|
|
.Select(x => new CandidateFamilyResponseItem
|
|
|
|
|
|
{
|
|
|
|
|
|
Marry = x.Marry,
|
|
|
|
|
|
MarryPrefix = x.MarryPrefix,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
MarryFirstName = x.MarryFirstName,
|
|
|
|
|
|
MarryLastName = x.MarryLastName,
|
|
|
|
|
|
FatherPrefix = x.FatherPrefix,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
FatherFirstName = x.FatherFirstName,
|
|
|
|
|
|
FatherLastName = x.FatherLastName,
|
|
|
|
|
|
MotherPrefix = x.MotherPrefix,
|
2023-03-24 11:50:46 +07:00
|
|
|
|
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
|
2023-03-23 21:41:26 +07:00
|
|
|
|
MotherFirstName = x.MotherFirstName,
|
|
|
|
|
|
MotherLastName = x.MotherLastName,
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<CandidateOccupationResponseItem?> GetsAsyncOccupation(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
var exam = await _context.PeriodExams.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
|
|
|
|
|
|
|
|
|
|
|
if (exam == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
|
|
|
|
|
|
.Select(x => new CandidateOccupationResponseItem
|
|
|
|
|
|
{
|
|
|
|
|
|
OccupationType = x.OccupationType,
|
|
|
|
|
|
OccupationCompany = x.OccupationCompany,
|
|
|
|
|
|
OccupationDepartment = x.OccupationDepartment,
|
|
|
|
|
|
OccupationEmail = x.OccupationEmail,
|
|
|
|
|
|
OccupationTelephone = x.OccupationTelephone,
|
|
|
|
|
|
})
|
|
|
|
|
|
.FirstOrDefaultAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Career?>> GetsAsyncCareer(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
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.Id == Guid.Parse(examId) && x.UserId == UserId);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Careers.AsQueryable()
|
|
|
|
|
|
.Where(x => x.Candidate == candidate)
|
|
|
|
|
|
.OrderBy(d => d.DurationStart)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Education?>> GetsAsyncEducation(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
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.Id == Guid.Parse(examId) && x.UserId == UserId);
|
|
|
|
|
|
|
|
|
|
|
|
return await _context.Educations.AsQueryable()
|
|
|
|
|
|
.Where(x => x.Candidate == candidate)
|
|
|
|
|
|
.OrderBy(d => d.DurationStart)
|
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<bool> GetsAsyncRegisterExam(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
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.Id == Guid.Parse(examId) && x.UserId == UserId);
|
|
|
|
|
|
|
|
|
|
|
|
return candidate != null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<string> CreateAsyncCandidate(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
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)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidate = new Candidate
|
|
|
|
|
|
{
|
|
|
|
|
|
PeriodExam = exam,
|
|
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
|
|
CreatedUserId = UserId ?? "",
|
|
|
|
|
|
LastUpdatedAt = DateTime.Now,
|
|
|
|
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
|
|
CreatedFullName = FullName ?? "",
|
|
|
|
|
|
LastUpdateFullName = FullName ?? "",
|
|
|
|
|
|
UserId = UserId ?? "",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _context.Candidates.AddAsync(candidate);
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
|
|
return candidate.Id.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_candidate.LastUpdatedAt = DateTime.Now;
|
|
|
|
|
|
_candidate.LastUpdateUserId = UserId ?? "";
|
|
|
|
|
|
_candidate.LastUpdateFullName = FullName ?? "";
|
|
|
|
|
|
return _candidate.Id.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncInformation(string examId, CandidateInformationResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
if (candidate == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.PrefixId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefix = await _context.Prefixes.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
|
|
|
|
|
|
|
|
|
|
|
|
if (prefix == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.PrefixNotFound);
|
|
|
|
|
|
candidate.Prefix = prefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.RelationshipId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var relationship = await _context.Relationships.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RelationshipId));
|
|
|
|
|
|
|
|
|
|
|
|
if (relationship == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.RelationshipNotFound);
|
|
|
|
|
|
candidate.Relationship = relationship;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-24 11:50:46 +07:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-23 21:41:26 +07:00
|
|
|
|
candidate.FirstName = updated.FirstName;
|
|
|
|
|
|
candidate.LastName = updated.LastName;
|
|
|
|
|
|
candidate.Nationality = updated.Nationality;
|
|
|
|
|
|
candidate.DateOfBirth = updated.DateOfBirth;
|
|
|
|
|
|
candidate.Email = updated.Email;
|
|
|
|
|
|
candidate.CitizenId = updated.CitizenId;
|
2023-03-24 11:50:46 +07:00
|
|
|
|
candidate.CitizenDate = updated.CitizenDate;
|
2023-03-23 21:41:26 +07:00
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncAddress(string examId, CandidateAddressResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
if (candidate == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistDistrictId));
|
|
|
|
|
|
|
|
|
|
|
|
if (registDistrict == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.DistrictNotFound);
|
|
|
|
|
|
candidate.RegistDistrict = registDistrict;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.RegistSubDistrictId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var registSubDistrict = await _context.SubDistricts.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistSubDistrictId));
|
|
|
|
|
|
|
|
|
|
|
|
if (registSubDistrict == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.SubDistrictNotFound);
|
|
|
|
|
|
candidate.RegistSubDistrict = registSubDistrict;
|
|
|
|
|
|
candidate.RegistZipCode = registSubDistrict.ZipCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentDistrictId));
|
|
|
|
|
|
|
|
|
|
|
|
if (currentDistrict == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.DistrictNotFound);
|
|
|
|
|
|
candidate.CurrentDistrict = currentDistrict;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.CurrentSubDistrictId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var currentSubDistrict = await _context.SubDistricts.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentSubDistrictId));
|
|
|
|
|
|
|
|
|
|
|
|
if (currentSubDistrict == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.SubDistrictNotFound);
|
|
|
|
|
|
candidate.CurrentSubDistrict = currentSubDistrict;
|
|
|
|
|
|
candidate.CurrentZipCode = currentSubDistrict.ZipCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
candidate.RegistAddress = updated.RegistAddress;
|
|
|
|
|
|
candidate.RegistSame = updated.RegistSame;
|
|
|
|
|
|
candidate.CurrentAddress = updated.CurrentAddress;
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncFamily(string examId, CandidateFamilyResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
if (candidate == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.MarryPrefixId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefix = await _context.Prefixes.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MarryPrefixId));
|
|
|
|
|
|
|
|
|
|
|
|
if (prefix == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.PrefixNotFound);
|
|
|
|
|
|
candidate.MarryPrefix = prefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.FatherPrefixId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefix = await _context.Prefixes.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.FatherPrefixId));
|
|
|
|
|
|
|
|
|
|
|
|
if (prefix == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.PrefixNotFound);
|
|
|
|
|
|
candidate.FatherPrefix = prefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (updated.MotherPrefixId != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var prefix = await _context.Prefixes.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MotherPrefixId));
|
|
|
|
|
|
|
|
|
|
|
|
if (prefix == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.PrefixNotFound);
|
|
|
|
|
|
candidate.MotherPrefix = prefix;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
candidate.Marry = updated.Marry;
|
|
|
|
|
|
candidate.MarryFirstName = updated.MarryFirstName;
|
|
|
|
|
|
candidate.MarryLastName = updated.MarryLastName;
|
|
|
|
|
|
candidate.FatherFirstName = updated.FatherFirstName;
|
|
|
|
|
|
candidate.FatherLastName = updated.FatherLastName;
|
|
|
|
|
|
candidate.MotherFirstName = updated.MotherFirstName;
|
|
|
|
|
|
candidate.MotherLastName = updated.MotherLastName;
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncOccupation(string examId, CandidateOccupationResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
if (candidate == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.ExamNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
candidate.OccupationType = updated.OccupationType;
|
|
|
|
|
|
candidate.OccupationCompany = updated.OccupationCompany;
|
|
|
|
|
|
candidate.OccupationDepartment = updated.OccupationDepartment;
|
|
|
|
|
|
candidate.OccupationEmail = updated.OccupationEmail;
|
|
|
|
|
|
candidate.OccupationTelephone = updated.OccupationTelephone;
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task CreateAsyncCareer(string examId, CandidateCareerResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
var career = new Career
|
|
|
|
|
|
{
|
|
|
|
|
|
Candidate = candidate,
|
|
|
|
|
|
Name = updated.Name,
|
|
|
|
|
|
Position = updated.Position,
|
|
|
|
|
|
Salary = updated.Salary,
|
|
|
|
|
|
DurationStart = updated.DurationStart,
|
|
|
|
|
|
DurationEnd = updated.DurationEnd,
|
|
|
|
|
|
Reason = updated.Reason,
|
|
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
|
|
CreatedUserId = UserId ?? "",
|
|
|
|
|
|
LastUpdatedAt = DateTime.Now,
|
|
|
|
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
|
|
CreatedFullName = FullName ?? "",
|
|
|
|
|
|
LastUpdateFullName = FullName ?? "",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _context.Careers.AddAsync(career);
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task CreateAsyncEducation(string examId, CandidateEducationResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var candidateId = await CreateAsyncCandidate(examId);
|
|
|
|
|
|
|
|
|
|
|
|
var candidate = await _context.Candidates.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
|
|
|
|
|
|
|
|
|
|
|
var educationLevel = await _context.EducationLevels.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.EducationLevelId));
|
|
|
|
|
|
|
|
|
|
|
|
if (educationLevel == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.EducationLevelNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
var education = new Education
|
|
|
|
|
|
{
|
|
|
|
|
|
Candidate = candidate,
|
|
|
|
|
|
EducationLevel = educationLevel,
|
|
|
|
|
|
Major = updated.Major,
|
|
|
|
|
|
Scores = updated.Scores,
|
|
|
|
|
|
Name = updated.Name,
|
|
|
|
|
|
DurationStart = updated.DurationStart,
|
|
|
|
|
|
DurationEnd = updated.DurationEnd,
|
|
|
|
|
|
CreatedAt = DateTime.Now,
|
|
|
|
|
|
CreatedUserId = UserId ?? "",
|
|
|
|
|
|
LastUpdatedAt = DateTime.Now,
|
|
|
|
|
|
LastUpdateUserId = UserId ?? "",
|
|
|
|
|
|
CreatedFullName = FullName ?? "",
|
|
|
|
|
|
LastUpdateFullName = FullName ?? "",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
await _context.Educations.AddAsync(education);
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncCareer(string careerId, CandidateCareerResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var career = await _context.Careers.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(careerId));
|
|
|
|
|
|
|
|
|
|
|
|
if (career == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.CareerNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
career.Name = updated.Name;
|
|
|
|
|
|
career.Position = updated.Position;
|
|
|
|
|
|
career.Salary = updated.Salary;
|
|
|
|
|
|
career.DurationStart = updated.DurationStart;
|
|
|
|
|
|
career.DurationEnd = updated.DurationEnd;
|
|
|
|
|
|
career.Reason = updated.Reason;
|
|
|
|
|
|
career.LastUpdatedAt = DateTime.Now;
|
|
|
|
|
|
career.LastUpdateUserId = UserId ?? "";
|
|
|
|
|
|
career.LastUpdateFullName = FullName ?? "";
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UpdateAsyncEducation(string educationId, CandidateEducationResponseItem updated)
|
|
|
|
|
|
{
|
|
|
|
|
|
var education = await _context.Educations.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(educationId));
|
|
|
|
|
|
|
|
|
|
|
|
if (education == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.EducationNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
var educationLevel = await _context.EducationLevels.AsQueryable()
|
|
|
|
|
|
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.EducationLevelId));
|
|
|
|
|
|
|
|
|
|
|
|
if (educationLevel == null)
|
|
|
|
|
|
throw new Exception(GlobalMessages.EducationLevelNotFound);
|
|
|
|
|
|
|
|
|
|
|
|
education.EducationLevel = educationLevel;
|
|
|
|
|
|
education.Major = updated.Major;
|
|
|
|
|
|
education.Scores = updated.Scores;
|
|
|
|
|
|
education.Name = updated.Name;
|
|
|
|
|
|
education.DurationStart = updated.DurationStart;
|
|
|
|
|
|
education.DurationEnd = updated.DurationEnd;
|
|
|
|
|
|
education.LastUpdatedAt = DateTime.Now;
|
|
|
|
|
|
education.LastUpdateUserId = UserId ?? "";
|
|
|
|
|
|
education.LastUpdateFullName = FullName ?? "";
|
|
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-24 11:50:46 +07:00
|
|
|
|
public async Task<string> GetStatusCandidateService(string examId)
|
|
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
return candidate.status;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task UserCheckCandidateService(string examId, string status)
|
2023-03-23 21:41:26 +07:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
2023-03-24 11:50:46 +07:00
|
|
|
|
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;
|
2023-03-23 21:41:26 +07:00
|
|
|
|
|
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|