From 0304e0594c217d13159bcc02e5c4c19f3fcfda24 Mon Sep 17 00:00:00 2001 From: harid Date: Thu, 18 Dec 2025 15:26:44 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=AA=E0=B8=A1=E0=B8=B1=E0=B8=84=E0=B8=A3?= =?UTF-8?q?=E0=B8=AA=E0=B8=AD=E0=B8=9A=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84?= =?UTF-8?q?=E0=B9=80=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=A3?= =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B0=E0=B8=8A=E0=B8=B2=E0=B8=8A=E0=B8=99?= =?UTF-8?q?=20+=20Status=20#2136?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Controllers/CandidateController.cs | 4 +- Services/CandidateService.cs | 70 +++++++++--------------------- 2 files changed, 23 insertions(+), 51 deletions(-) diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs index f6852cb..751c6af 100644 --- a/Controllers/CandidateController.cs +++ b/Controllers/CandidateController.cs @@ -1559,12 +1559,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } /// - /// โหลดใบชำระเงิน + /// กรอกเลขประจำตัวประชาชน /// /// รหัสรอบสมัคร /// Id ตำแหน่งสมัครสอบ /// - /// เมื่อทำการโหลดใบชำระเงิน สำเร็จ + /// เมื่อกรอกเลขประจำตัวประชาชน สำเร็จ /// ไม่ได้ Login เข้าระบบ /// เมื่อเกิดข้อผิดพลาดในการทำงาน [HttpPut("check/citizen/{examId:length(36)}/{positionId:length(36)}")] diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 8fe7f31..dd90ae6 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -2600,64 +2600,42 @@ namespace BMA.EHR.Recurit.Exam.Service.Services public async Task CheckCitizen(string examId, string positionId, string citizenId) { + // เช็ครอบสมัครสอบ var exam = await _context.PeriodExams.AsQueryable() .Where(p => p.CheckDisability == false) .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId)); - if (exam == null) throw new Exception(GlobalMessages.ExamNotFound); - #region check digit (old) - // if (citizenId.Length != 13) - // throw new Exception(GlobalMessages.CitizenIncomplete); - - // int[] citizenIdDigits = citizenId.Select(c => int.Parse(c.ToString())).ToArray(); - // int cal = - // citizenIdDigits[0] * 13 + - // citizenIdDigits[1] * 12 + - // citizenIdDigits[2] * 11 + - // citizenIdDigits[3] * 10 + - // citizenIdDigits[4] * 9 + - // citizenIdDigits[5] * 8 + - // citizenIdDigits[6] * 7 + - // citizenIdDigits[7] * 6 + - // citizenIdDigits[8] * 5 + - // citizenIdDigits[9] * 4 + - // citizenIdDigits[10] * 3 + - // citizenIdDigits[11] * 2; - - // int calStp2 = cal % 11; - // int chkDigit = 11 - calStp2; - - // if (chkDigit >= 10) - // { - // chkDigit = 0; - // } - - // if (citizenIdDigits[12] != chkDigit) - // throw new Exception(GlobalMessages.CitizenIncorrect); - #endregion - + // เช็คตำแหน่งที่สมัครสอบ if (positionId != "00000000-0000-0000-0000-000000000000") { var position = await _context.PositionExams.AsQueryable() - .FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam); - + .FirstOrDefaultAsync(x => x.Id == Guid.Parse(positionId) && x.PeriodExam == exam); if (position == null) throw new Exception(GlobalMessages.PositionExamNotFound); + } + + // เช็คเลขบัตรซ้ำ + var candidate = await _context.Candidates.AsQueryable() + .Where(x => + x.PeriodExam == exam + && x.UserId != UserId + && x.CitizenId == citizenId + && ( + (exam.Fee > 0 && x.Status.Trim().ToUpper() != "REGISTER") + || (exam.Fee == 0 && x.Status.Trim().ToUpper() == "CHECKSEAT") + ) + ) + .FirstOrDefaultAsync(); + if (candidate != null) + throw new Exception(GlobalMessages.CitizanDupicate); - //var candidate1 = await _context.Candidates.AsQueryable() - // .Where(x => x.PeriodExam == exam && x.UserId != UserId /*&& x.PositionExam == position*/ && x.CitizenId == citizenId) - // .FirstOrDefaultAsync(); - //if (candidate1 != null) - // throw new Exception(GlobalMessages.CitizanDupicate); - //return; - } - + // เช็ค Digit เลขบัตร var apiUrl = $"{_configuration["API"]}/org/dotnet/check-citizen"; using (var client = new HttpClient()) { - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", "")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token?.Replace("Bearer ", "")); client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]); var _res = await client.PostAsJsonAsync(apiUrl, new { @@ -2669,12 +2647,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services throw new Exception(jsonData?["message"]?.ToString()); } - var candidate2 = await _context.Candidates.AsQueryable() - .Where(x => x.PeriodExam == exam && x.UserId != UserId && x.CitizenId == citizenId) - .FirstOrDefaultAsync(); - if (candidate2 != null) - throw new Exception(GlobalMessages.CitizanDupicate); - return; }