From 4c3b15c72bc13da35573b649ae56b06ef9e71730 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 30 Mar 2023 13:42:54 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9A=E0=B8=B1=E0=B8=99=E0=B8=97=E0=B8=B6?= =?UTF-8?q?=E0=B8=81=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5?= =?UTF-8?q?=E0=B8=AA=E0=B8=A1=E0=B8=B1=E0=B8=84=E0=B8=A3=E0=B8=AA=E0=B8=AD?= =?UTF-8?q?=E0=B8=9A=E0=B8=97=E0=B8=B1=E0=B9=89=E0=B8=87=E0=B8=AB=E0=B8=A1?= =?UTF-8?q?=E0=B8=94=E0=B8=A3=E0=B8=A7=E0=B8=A1=E0=B9=80=E0=B8=9B=E0=B9=87?= =?UTF-8?q?=E0=B8=991api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/CandidateController.cs | 26 +++++ Response/CandidateResponseItem.cs | 72 ++++++++++++ Services/CandidateService.cs | 181 +++++++++++++++++++++++++++++ 3 files changed, 279 insertions(+) create mode 100644 Response/CandidateResponseItem.cs diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs index 2d235b0..e8f9c6c 100644 --- a/Controllers/CandidateController.cs +++ b/Controllers/CandidateController.cs @@ -267,6 +267,32 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } } + /// + /// อัพเดทข้อมูล ข้อมูลส่วนตัว ผู้สมัคร + /// + /// ข้อมูลส่วนตัว + /// + /// เมื่อทำการอัพเดทข้อมูล ข้อมูลส่วนตัว ผู้สมัคร สำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPost("{examId:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> UpdateAsync(string examId, CandidateResponseItem candidateInformation) + { + try + { + await _candidateService.UpdateAsync(examId, candidateInformation); + + return Success(); + } + catch (Exception ex) + { + return Error(ex); + } + } + /// /// อัพเดทข้อมูล ข้อมูลส่วนตัว ผู้สมัคร /// diff --git a/Response/CandidateResponseItem.cs b/Response/CandidateResponseItem.cs new file mode 100644 index 0000000..34c3977 --- /dev/null +++ b/Response/CandidateResponseItem.cs @@ -0,0 +1,72 @@ + +namespace BMA.EHR.Recurit.Exam.Service.Response +{ + public class CandidateResponseItem + { + public Models.Prefix? Prefix { get; set; } + public string? PrefixId { get; set; } + public string? FirstName { get; set; } = string.Empty; + public string? LastName { get; set; } = string.Empty; + public string? Nationality { get; set; } = string.Empty; + public DateTime? DateOfBirth { get; set; } + public Models.Relationship? Relationship { get; set; } + public string? RelationshipId { get; set; } + public string? Email { get; set; } = string.Empty; + public string? CitizenId { get; set; } = string.Empty; + public Models.Province? CitizenProvince { get; set; } + public string? CitizenProvinceId { get; set; } + public Models.District? CitizenDistrict { get; set; } + public string? CitizenDistrictId { get; set; } + public DateTime? CitizenDate { get; set; } + public string? Telephone { get; set; } + public string? MobilePhone { get; set; } + public string? Knowledge { get; set; } + public string? RegistAddress { get; set; } + public Models.Province? RegistProvince { get; set; } + public string? RegistProvinceId { get; set; } + public Models.District? RegistDistrict { get; set; } + public string? RegistDistrictId { get; set; } + public Models.SubDistrict? RegistSubDistrict { get; set; } + public string? RegistSubDistrictId { get; set; } + public string? RegistZipCode { get; set; } + public bool? RegistSame { get; set; } + public string? CurrentAddress { get; set; } + public Models.Province? CurrentProvince { get; set; } + public string? CurrentProvinceId { get; set; } + public Models.District? CurrentDistrict { get; set; } + public string? CurrentDistrictId { get; set; } + public Models.SubDistrict? CurrentSubDistrict { get; set; } + public string? CurrentSubDistrictId { get; set; } + public string? CurrentZipCode { get; set; } + public bool? Marry { get; set; } + public Models.Prefix? MarryPrefix { get; set; } + public string? MarryPrefixId { get; set; } + public string? MarryFirstName { get; set; } + public string? MarryLastName { get; set; } + public string? MarryOccupation { get; set; } + public string? MarryNationality { get; set; } + public Models.Prefix? FatherPrefix { get; set; } + public string? FatherPrefixId { get; set; } + public string? FatherFirstName { get; set; } + public string? FatherLastName { get; set; } + public string? FatherOccupation { get; set; } + public string? FatherNationality { get; set; } + public Models.Prefix? MotherPrefix { get; set; } + public string? MotherPrefixId { get; set; } + public string? MotherFirstName { get; set; } + public string? MotherLastName { get; set; } + public string? MotherOccupation { get; set; } + public string? MotherNationality { get; set; } + public string? OccupationType { get; set; } + + public string? OccupationCompany { get; set; } + + public string? OccupationDepartment { get; set; } + + public string? OccupationEmail { get; set; } + + public string? OccupationTelephone { get; set; } + + public string? OccupationPosition { get; set; } + } +} diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 2d4b7dd..2913678 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -278,6 +278,187 @@ namespace BMA.EHR.Recurit.Exam.Service.Services } } + public async Task UpdateAsync(string examId, CandidateResponseItem 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; + } + + 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; + } + + 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; + } + + 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.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; + candidate.Telephone = updated.Telephone; + candidate.MobilePhone = updated.MobilePhone; + candidate.Knowledge = updated.Knowledge; + + candidate.RegistAddress = updated.RegistAddress; + candidate.RegistSame = updated.RegistSame == null ? null : updated.RegistSame; + candidate.CurrentAddress = updated.CurrentAddress; + + candidate.Marry = updated.Marry == null ? null : updated.Marry; + candidate.MarryFirstName = updated.MarryFirstName; + candidate.MarryLastName = updated.MarryLastName; + candidate.MarryOccupation = updated.MarryOccupation; + candidate.MarryNationality = updated.MarryNationality; + candidate.FatherFirstName = updated.FatherFirstName; + candidate.FatherLastName = updated.FatherLastName; + candidate.FatherOccupation = updated.FatherOccupation; + candidate.FatherNationality = updated.FatherNationality; + candidate.MotherFirstName = updated.MotherFirstName; + candidate.MotherLastName = updated.MotherLastName; + candidate.MotherOccupation = updated.MotherOccupation; + candidate.MotherNationality = updated.MotherNationality; + + candidate.OccupationType = updated.OccupationType; + candidate.OccupationCompany = updated.OccupationCompany; + candidate.OccupationDepartment = updated.OccupationDepartment; + candidate.OccupationEmail = updated.OccupationEmail; + candidate.OccupationTelephone = updated.OccupationTelephone; + candidate.OccupationPosition = updated.OccupationPosition; + + await _context.SaveChangesAsync(); + } + public async Task UpdateAsyncInformation(string examId, CandidateInformationResponseItem updated) { var candidateId = await CreateAsyncCandidate(examId);