From 5c3c9739d17c88a3ad4977e6aabfd68d19ce22a7 Mon Sep 17 00:00:00 2001 From: mahan Date: Mon, 19 Jan 2026 15:30:28 +0330 Subject: [PATCH] fix regex and validation for rollcall history case details --- .../Repository/RollCallRepository.cs | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/CompanyManagment.EFCore/Repository/RollCallRepository.cs b/CompanyManagment.EFCore/Repository/RollCallRepository.cs index eb5e40f7..f0758afb 100644 --- a/CompanyManagment.EFCore/Repository/RollCallRepository.cs +++ b/CompanyManagment.EFCore/Repository/RollCallRepository.cs @@ -20,6 +20,7 @@ using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; using _0_Framework.Exceptions; +using OfficeOpenXml.Packaging.Ionic.Zip; namespace CompanyManagment.EFCore.Repository; @@ -2297,26 +2298,33 @@ public class RollCallRepository : RepositoryBase, IRollCallRepos //این برای این هست که اگر بر اساس پرسنل جستجو شده بود و در titleId اگر به فرمت YYYY_MM اومد به این معنی هست که باید بر طبق ماه فیلتر بشه نه به صورت روزانه if (searchModel.EmployeeId is > 0) { - //TODO: set correct regex. - // if (!Regex.IsMatch(titleId, "")) - // throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + if (!Regex.IsMatch(titleId, @"^\d{4}_\d{2}$")) + throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + var splitDate = titleId.Split("_"); var year = Convert.ToInt32(splitDate.First()); var month = Convert.ToInt32(splitDate.Last()); var startDateFa = $"{year:D4}/{month:D2}/01"; + if (!startDateFa.TryToGeorgianDateTime(out startDate)) + { + throw new BadRequestException("تاریخ وارد شده نامعتبر است"); + } + var endDateFa = startDateFa.FindeEndOfMonth(); - - startDate = startDateFa.ToGeorgianDateTime(); - endDate = endDateFa.ToGeorgianDateTime(); + + if (!endDateFa.TryToGeorgianDateTime(out endDate)) + { + throw new BadRequestException("تاریخ وارد شده نامعتبر است"); + } query = query .Where(x => x.RollCallEmployee.EmployeeId == searchModel.EmployeeId); } else { - //TODO: set correct regex. - // if (!Regex.IsMatch(titleId, "")) - // throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + if (!Regex.IsMatch(titleId, @"^\d{4}/\d{2}/\d{2}$")) + throw new BadRequestException("شناسه سر تیتر وارد شده نامعتبر است"); + startDate = titleId.ToGeorgianDateTime(); endDate = startDate;