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;
}