From 540130f52cd5e86ef6d862e7310717d336a04843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nut=2E=E0=B9=84=E0=B8=9B=E0=B9=80=E0=B8=A3=E0=B8=B7?= =?UTF-8?q?=E0=B9=88=E0=B8=AD=E0=B8=A2?= Date: Tue, 8 Sep 2026 12:48:44 +0700 Subject: [PATCH] fix(form_1_2): guard null date/start_working before .Value to prevent 500 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetForm2Report ("ร1. แบบฟอร์มเสนอขอปรับเปลี่ยนชื่อตำแหน่ง") called .Value on nullable DateTime fields unconditionally, crashing with InvalidOperationException whenever a record's date or start_working was null — exactly what happened for form_1_2_uid 377a46dc-7131-4b58-ac7e-c9b54900ac34 (date is null in production). Mirrors the null-check pattern the sibling GetForm3Report already uses for the same kind of field. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_0153wBt23EjW125ZsADwWVAs --- Controllers/RoFive.Controller.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Controllers/RoFive.Controller.cs b/Controllers/RoFive.Controller.cs index e057e99..e8c03f9 100644 --- a/Controllers/RoFive.Controller.cs +++ b/Controllers/RoFive.Controller.cs @@ -4113,13 +4113,19 @@ namespace rmutr_report.Controllers public IActionResult GetForm2Report([FromRoute] string type, [FromBody] form_1_2 form1) { - form1.dates = form1.date.Value.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("th-TH")); - form1.day_start_workings = - form1.start_working.Value.ToString("dd", CultureInfo.CreateSpecificCulture("th-TH")); - form1.month_start_workings = - form1.start_working.Value.ToString("MMMM", CultureInfo.CreateSpecificCulture("th-TH")); - form1.year_start_workings = - form1.start_working.Value.ToString("yyyy", CultureInfo.CreateSpecificCulture("th-TH")); + if (form1.date != null) + { + form1.dates = form1.date.Value.ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("th-TH")); + } + if (form1.start_working != null) + { + form1.day_start_workings = + form1.start_working.Value.ToString("dd", CultureInfo.CreateSpecificCulture("th-TH")); + form1.month_start_workings = + form1.start_working.Value.ToString("MMMM", CultureInfo.CreateSpecificCulture("th-TH")); + form1.year_start_workings = + form1.start_working.Value.ToString("yyyy", CultureInfo.CreateSpecificCulture("th-TH")); + } var form_1 = new List() { form1 }; Report report = new Report();