From 75e2a3c5580fa522d5cada90109e2585777c5752 Mon Sep 17 00:00:00 2001 From: SamSys Date: Sat, 28 Jun 2025 13:33:52 +0330 Subject: [PATCH] Create Employee Validation for InsuranceHistory --- 0_Framework/Application/Tools.cs | 10 +++++++++- .../Pages/Company/Employees/Index.cshtml.cs | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/0_Framework/Application/Tools.cs b/0_Framework/Application/Tools.cs index f28e3246..76c9bdda 100644 --- a/0_Framework/Application/Tools.cs +++ b/0_Framework/Application/Tools.cs @@ -880,7 +880,15 @@ public static class Tools } } - numbers = Convert.ToInt32(num); + try + { + numbers = Convert.ToInt32(num); + } + catch (Exception e) + { + return 0; + } + return numbers; } public static string ToFarsiMonthByNumber(this string value) diff --git a/ServiceHost/Areas/Admin/Pages/Company/Employees/Index.cshtml.cs b/ServiceHost/Areas/Admin/Pages/Company/Employees/Index.cshtml.cs index 53bd9e0b..d6686dcd 100644 --- a/ServiceHost/Areas/Admin/Pages/Company/Employees/Index.cshtml.cs +++ b/ServiceHost/Areas/Admin/Pages/Company/Employees/Index.cshtml.cs @@ -222,6 +222,23 @@ public class IndexModel : PageModel if (string.IsNullOrWhiteSpace(command.MaritalStatus)) return new JsonResult(result.Failed("لطفا وضعیت تاهل را مشخص نمایید")); + if (string.IsNullOrWhiteSpace(command.InsuranceHistoryByYear) || string.IsNullOrWhiteSpace(command.InsuranceHistoryByMonth)) + return new JsonResult(result.Failed("لطفا سابقه بیمه را مشخص نمایید")); + if (command.InsuranceHistoryByYear != "0") + { + var insuranceYear = command.InsuranceHistoryByYear.ExtractIntNumbers(); + if(insuranceYear == 0) + return new JsonResult(result.Failed("لطفا سال را به عدد وارد کنید")); + } + + if (command.InsuranceHistoryByMonth != "0") + { + var insuranceMonth = command.InsuranceHistoryByMonth.ExtractIntNumbers(); + if (insuranceMonth == 0) + return new JsonResult(result.Failed("لطفا ماه را به عدد وارد کنید")); + } + + result = _employeeApplication.Create(command); Thread.Sleep(1000);