เพิ่มฟิวตำแหน่งตอนสร้างรอบสมัคร

This commit is contained in:
Kittapath 2023-04-05 00:58:22 +07:00
parent dee47f326d
commit bed23f911a
19 changed files with 3228 additions and 568 deletions

View file

@ -67,7 +67,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return candidate;
}
public async Task<CandidateInformationResponseItem?> GetsAsyncInformation(string examId)
public async Task<CandidateInformationResponseItem?> GetsAsyncInformation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -75,33 +75,69 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
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,
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,
Telephone = x.Telephone,
MobilePhone = x.MobilePhone,
Knowledge = x.Knowledge,
})
.FirstOrDefaultAsync();
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);
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.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,
Telephone = x.Telephone,
MobilePhone = x.MobilePhone,
Knowledge = x.Knowledge,
})
.FirstOrDefaultAsync();
}
else
{
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.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,
Telephone = x.Telephone,
MobilePhone = x.MobilePhone,
Knowledge = x.Knowledge,
})
.FirstOrDefaultAsync();
}
}
public async Task<CandidateAddressResponseItem?> GetsAsyncAddress(string examId)
public async Task<CandidateAddressResponseItem?> GetsAsyncAddress(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -109,32 +145,67 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
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,
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();
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);
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.Select(x => new CandidateAddressResponseItem
{
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();
}
else
{
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.Select(x => new CandidateAddressResponseItem
{
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();
}
}
public async Task<CandidateFamilyResponseItem?> GetsAsyncFamily(string examId)
public async Task<CandidateFamilyResponseItem?> GetsAsyncFamily(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -142,34 +213,71 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
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,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
MotherNationality = x.MotherNationality,
})
.FirstOrDefaultAsync();
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);
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.Select(x => new CandidateFamilyResponseItem
{
Marry = x.Marry,
MarryPrefix = x.MarryPrefix,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
MotherNationality = x.MotherNationality,
})
.FirstOrDefaultAsync();
}
else
{
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.Select(x => new CandidateFamilyResponseItem
{
Marry = x.Marry,
MarryPrefix = x.MarryPrefix,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
MotherNationality = x.MotherNationality,
})
.FirstOrDefaultAsync();
}
}
public async Task<CandidateOccupationResponseItem?> GetsAsyncOccupation(string examId)
public async Task<CandidateOccupationResponseItem?> GetsAsyncOccupation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -177,21 +285,45 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
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,
OccupationPosition = x.OccupationPosition,
})
.FirstOrDefaultAsync();
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);
return await _context.Candidates.AsQueryable()
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.Select(x => new CandidateOccupationResponseItem
{
OccupationType = x.OccupationType,
OccupationCompany = x.OccupationCompany,
OccupationDepartment = x.OccupationDepartment,
OccupationEmail = x.OccupationEmail,
OccupationTelephone = x.OccupationTelephone,
OccupationPosition = x.OccupationPosition,
})
.FirstOrDefaultAsync();
}
else
{
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,
OccupationPosition = x.OccupationPosition,
})
.FirstOrDefaultAsync();
}
}
public async Task<IEnumerable<Career?>> GetsAsyncCareer(string examId)
public async Task<IEnumerable<Career?>> GetsAsyncCareer(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -202,13 +334,28 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return await _context.Careers.AsQueryable()
.Where(x => x.Candidate == candidate)
.OrderBy(d => d.DurationStart)
.ToListAsync();
}
public async Task<IEnumerable<Education?>> GetsAsyncEducation(string examId)
public async Task<IEnumerable<Education?>> GetsAsyncEducation(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -219,6 +366,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return await _context.Educations.AsQueryable()
.Include(x => x.EducationLevel)
.Where(x => x.Candidate == candidate)
@ -226,7 +388,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.ToListAsync();
}
public async Task<IEnumerable<FileListResponse?>> GetsAsyncFileUpload(string examId)
public async Task<IEnumerable<FileListResponse?>> GetsAsyncFileUpload(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -237,6 +399,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return await _context.CandidateDocuments.AsQueryable()
.Where(x => x.Candidate == candidate)
.Select(x => new FileListResponse
@ -246,10 +423,10 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
FileType = x.Document == null ? "" : x.Document.FileType,
FileSize = x.Document == null ? 0 : x.Document.FileSize,
})
.ToListAsync(); ;
.ToListAsync();
}
public async Task<string> GetsAsyncProfileImage(string examId)
public async Task<string> GetsAsyncProfileImage(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -262,13 +439,27 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.FirstOrDefaultAsync();
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);
candidate = await _context.Candidates.AsQueryable()
.Include(x => x.ProfileImg)
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.FirstOrDefaultAsync();
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return candidate.ProfileImg == null ? "" : candidate.ProfileImg.Id.ToString();
}
public async Task<string> GetsAsyncPaymentImg(string examId)
public async Task<string> GetsAsyncPaymentImg(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -281,13 +472,27 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.FirstOrDefaultAsync();
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);
candidate = await _context.Candidates.AsQueryable()
.Include(x => x.PaymentImg)
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.FirstOrDefaultAsync();
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return candidate.PaymentImg == null ? "" : candidate.PaymentImg.Id.ToString();
}
public async Task<bool> GetsAsyncRegisterExam(string examId)
public async Task<RequestStatusRegistry> GetsAsyncRegisterExam(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -298,10 +503,31 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
return candidate != null;
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
var candidatePosition = await _context.Candidates.AsQueryable()
.Include(x => x.PositionExam)
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.Status != "register" && x.Status != "rejectRegister");
return new RequestStatusRegistry
{
Consend = candidate != null,
Status = candidate == null ? null : candidate.Status,
PositionExam = candidatePosition?.PositionExam
};
}
public async Task<string> CreateAsyncCandidate(string examId)
public async Task<string> CreateAsyncCandidate(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -309,11 +535,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (exam == null)
throw new Exception(GlobalMessages.ExamNotFound);
var _candidateNumber = await _context.Candidates.AsQueryable()
.CountAsync(x => x.PeriodExam == exam);
var _candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
_candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (_candidate == null)
{
var candidate = new Candidate
@ -326,13 +562,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
CreatedFullName = FullName ?? "",
LastUpdateFullName = FullName ?? "",
UserId = UserId ?? "",
SeatNumber = "CDC-" + (_candidateNumber + 1),
};
await _context.Candidates.AddAsync(candidate);
await _context.SaveChangesAsync();
return candidate.Id.ToString();
}
else
@ -344,9 +576,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
}
}
public async Task UpdateAsync(string examId, CandidateResponseItem updated)
public async Task UpdateAsync(string examId, string positionId, CandidateResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -361,6 +593,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.Prefix = prefix;
}
@ -371,6 +604,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (relationship == null)
throw new Exception(GlobalMessages.RelationshipNotFound);
candidate.Relationship = relationship;
}
@ -381,6 +615,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (citizenProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CitizenProvince = citizenProvince;
}
@ -391,6 +626,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (citizenDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CitizenDistrict = citizenDistrict;
}
@ -401,6 +637,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.RegistProvince = registProvince;
}
@ -411,6 +648,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.RegistDistrict = registDistrict;
}
@ -421,6 +659,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.RegistSubDistrict = registSubDistrict;
candidate.RegistZipCode = registSubDistrict.ZipCode;
}
@ -432,6 +671,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CurrentProvince = currentProvince;
}
@ -442,6 +682,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CurrentDistrict = currentDistrict;
}
@ -452,6 +693,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.CurrentSubDistrict = currentSubDistrict;
candidate.CurrentZipCode = currentSubDistrict.ZipCode;
}
@ -463,6 +705,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MarryPrefix = prefix;
}
@ -473,6 +716,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.FatherPrefix = prefix;
}
@ -483,6 +727,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MotherPrefix = prefix;
}
@ -525,9 +770,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncInformation(string examId, CandidateInformationResponseItem updated)
public async Task UpdateAsyncInformation(string examId, string positionId, CandidateInformationResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -542,6 +787,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.Prefix = prefix;
}
@ -552,6 +798,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (relationship == null)
throw new Exception(GlobalMessages.RelationshipNotFound);
candidate.Relationship = relationship;
}
@ -562,6 +809,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (citizenProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CitizenProvince = citizenProvince;
}
@ -572,6 +820,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (citizenDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CitizenDistrict = citizenDistrict;
}
@ -589,9 +838,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncProfileImage(string examId, IFormFile file)
public async Task UpdateAsyncProfileImage(string examId, string positionId, IFormFile file)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.ProfileImg)
@ -614,9 +863,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncAddress(string examId, CandidateAddressResponseItem updated)
public async Task UpdateAsyncAddress(string examId, string positionId, CandidateAddressResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -631,6 +880,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.RegistProvince = registProvince;
}
@ -641,6 +891,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.RegistDistrict = registDistrict;
}
@ -651,6 +902,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (registSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.RegistSubDistrict = registSubDistrict;
candidate.RegistZipCode = registSubDistrict.ZipCode;
}
@ -662,6 +914,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CurrentProvince = currentProvince;
}
@ -672,6 +925,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CurrentDistrict = currentDistrict;
}
@ -682,6 +936,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (currentSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.CurrentSubDistrict = currentSubDistrict;
candidate.CurrentZipCode = currentSubDistrict.ZipCode;
}
@ -693,9 +948,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncFamily(string examId, CandidateFamilyResponseItem updated)
public async Task UpdateAsyncFamily(string examId, string positionId, CandidateFamilyResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -710,6 +965,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MarryPrefix = prefix;
}
@ -720,6 +976,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.FatherPrefix = prefix;
}
@ -730,6 +987,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MotherPrefix = prefix;
}
@ -750,9 +1008,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncOccupation(string examId, CandidateOccupationResponseItem updated)
public async Task UpdateAsyncOccupation(string examId, string positionId, CandidateOccupationResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -770,9 +1028,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncDocument(string examId, IFormFile file)
public async Task UpdateAsyncDocument(string examId, string positionId, IFormFile file)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -785,6 +1043,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var document = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (document == null)
throw new Exception(GlobalMessages.NoFileToUpload);
var candidateDocument = new CandidateDocument
{
Candidate = candidate,
@ -800,9 +1061,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
}
public async Task CreateAsyncCareer(string examId, CandidateCareerResponseItem updated)
public async Task CreateAsyncCareer(string examId, string positionId, CandidateCareerResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -825,13 +1086,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
};
await _context.Careers.AddAsync(career);
await _context.SaveChangesAsync();
}
public async Task CreateAsyncEducation(string examId, CandidateEducationResponseItem updated)
public async Task CreateAsyncEducation(string examId, string positionId, CandidateEducationResponseItem updated)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
@ -860,7 +1120,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
};
await _context.Educations.AddAsync(education);
await _context.SaveChangesAsync();
}
@ -938,7 +1197,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task<string> GetStatusCandidateService(string examId)
public async Task<string> GetStatusCandidateService(string examId, string positionId)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -949,13 +1208,25 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
return candidate.Status;
}
public async Task UserCheckCandidateService(string examId, string status)
public async Task UserCheckCandidateService(string examId, string positionId, string status)
{
var exam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -966,6 +1237,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId);
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);
candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position);
}
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
@ -977,11 +1260,15 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task AdminCheckCandidateService(string candidateId, string status, RequestApprove item)
{
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.PeriodExam)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
if (candidate == null)
throw new Exception(GlobalMessages.CandidateNotFound);
if (candidate.PeriodExam == null)
throw new Exception(GlobalMessages.ExamNotFound);
if (status != "rejectDelete")
{
candidate.Status = status;
@ -989,6 +1276,10 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
{
candidate.RejectDetail = item.Reason;
}
else if (status == "payment" && candidate.PeriodExam.Fee == 0)
{
candidate.Status = "checkSeat";
}
}
else
{
@ -1011,9 +1302,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
await _context.SaveChangesAsync();
}
public async Task UpdateAsyncPaymentImage(string examId, IFormFile file)
public async Task UpdateAsyncPaymentImage(string examId, string positionId, IFormFile file)
{
var candidateId = await CreateAsyncCandidate(examId);
var candidateId = await CreateAsyncCandidate(examId, positionId);
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.PaymentImg)

View file

@ -2,6 +2,7 @@
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;
@ -61,18 +62,29 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
return periodExam;
}
public async Task CreateAsync(PeriodExam inserted)
public async Task CreateAsync(RequestPeriodExam inserted)
{
var periodExam = new PeriodExam
{
Name = inserted.Name,
StartDate = inserted.StartDate,
EndDate = inserted.EndDate,
CheckDocument = inserted.CheckDocument,
CheckDisability = inserted.CheckDisability,
Round = inserted.Round,
Fee = inserted.Fee,
Year = inserted.Year,
Fee = inserted.Fee,
RegisterStartDate = inserted.RegisterStartDate,
RegisterEndDate = inserted.RegisterEndDate,
PaymentStartDate = inserted.PaymentStartDate,
PaymentEndDate = inserted.PaymentEndDate,
AnnouncementStartDate = inserted.AnnouncementStartDate,
AnnouncementEndDate = inserted.AnnouncementEndDate,
OrganizationCodeId = inserted.OrganizationCodeId,
OrganizationCodeName = inserted.OrganizationCodeName,
OrganizationId = inserted.OrganizationId,
OrganizationName = inserted.OrganizationName,
PaymentKrungThai = inserted.PaymentKrungThai,
Detail = inserted.Detail,
AnnounceDate = inserted.AnnounceDate,
Note = inserted.Note,
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
@ -81,12 +93,48 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
LastUpdateFullName = FullName ?? "",
};
foreach (var bank in inserted.BankExam)
{
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);
}
foreach (var position in inserted.PositionExam)
{
var positionExam = new PositionExam
{
PeriodExam = periodExam,
PositionId = position.PositionId,
PositionName = position.PositionName,
TypeName = position.TypeName,
CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "",
CreatedFullName = FullName ?? "",
LastUpdateFullName = FullName ?? "",
};
await _context.PositionExams.AddAsync(positionExam);
}
await _context.PeriodExams.AddAsync(periodExam);
await _context.SaveChangesAsync();
}
public async Task UpdateAsync(string examId, PeriodExam updated)
public async Task UpdateAsync(string examId, RequestPeriodExam updated)
{
var periodExam = await _context.PeriodExams.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
@ -95,16 +143,29 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
throw new Exception(GlobalMessages.ExamNotFound);
periodExam.Name = updated.Name;
periodExam.StartDate = updated.StartDate;
periodExam.EndDate = updated.EndDate;
periodExam.CheckDocument = updated.CheckDocument;
periodExam.CheckDisability = updated.CheckDisability;
periodExam.Round = updated.Round;
periodExam.Fee = updated.Fee;
periodExam.Year = updated.Year;
periodExam.Fee = updated.Fee;
periodExam.RegisterStartDate = updated.RegisterStartDate;
periodExam.RegisterEndDate = updated.RegisterEndDate;
periodExam.PaymentStartDate = updated.PaymentStartDate;
periodExam.PaymentEndDate = updated.PaymentEndDate;
periodExam.AnnouncementStartDate = updated.AnnouncementStartDate;
periodExam.AnnouncementEndDate = updated.AnnouncementEndDate;
periodExam.OrganizationCodeId = updated.OrganizationCodeId;
periodExam.OrganizationCodeName = updated.OrganizationCodeName;
periodExam.OrganizationId = updated.OrganizationId;
periodExam.OrganizationName = updated.OrganizationName;
periodExam.PaymentKrungThai = updated.PaymentKrungThai;
periodExam.Detail = updated.Detail;
periodExam.AnnounceDate = updated.AnnounceDate;
periodExam.IsActive = updated.IsActive;
periodExam.Note = updated.Note;
periodExam.CreatedAt = DateTime.Now;
periodExam.CreatedUserId = UserId ?? "";
periodExam.LastUpdatedAt = DateTime.Now;
periodExam.LastUpdateUserId = UserId ?? "";
periodExam.CreatedFullName = FullName ?? "";
periodExam.LastUpdateFullName = FullName ?? "";
await _context.SaveChangesAsync();