From 4df68a56056eb05a8b433bacf5c081c1007f0625 Mon Sep 17 00:00:00 2001 From: Bright Date: Tue, 21 May 2024 14:17:11 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B9=80?= =?UTF-8?q?=E0=B8=A5=E0=B8=82=E0=B8=9A=E0=B8=B1=E0=B8=95=E0=B8=A3=20?= =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1/=E0=B9=81?= =?UTF-8?q?=E0=B8=81=E0=B9=89=E0=B9=84=E0=B8=82=E0=B8=A3=E0=B8=B1=E0=B8=9A?= =?UTF-8?q?=E0=B9=82=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementReceiveController.cs | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs index 0a792bbd..7fdf6176 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementReceiveController.cs @@ -404,6 +404,41 @@ namespace BMA.EHR.Placement.Service.Controllers LastUpdateUserId = UserId ?? "", LastUpdatedAt = DateTime.Now, }; + if (placementReceive.citizenId.Length != 13) + { + return Error("กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก", 500); + } + int[] citizenIdDigits = placementReceive.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 = 1; + } + else if (chkDigit == 11) + { + chkDigit = chkDigit % 10; + } + + if (citizenIdDigits[12] != chkDigit) + { + return Error("ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง", 500); + } var apiUrl = $"{_configuration["API"]}org/profile/citizenid/position/{req.citizenId}"; using (var client = new HttpClient()) @@ -629,6 +664,41 @@ namespace BMA.EHR.Placement.Service.Controllers .FirstOrDefaultAsync(x => x.Id == id); if (uppdated == null) return Error(GlobalMessages.PlacementReceiveNotFound, 404); + if (req.citizenId.Length != 13) + { + return Error("กรุณากรอกข้อมูลรหัสบัตรประจำตัวประชาชนให้ครบ 13 หลัก", 500); + } + int[] citizenIdDigits = req.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 = 1; + } + else if (chkDigit == 11) + { + chkDigit = chkDigit % 10; + } + + if (citizenIdDigits[12] != chkDigit) + { + return Error("ข้อมูลรหัสบัตรประจำตัวประชาชนไม่ถูกต้อง", 500); + } if (req.RelationshipId != null) {