fix regex and validation for rollcall history case details

This commit is contained in:
2026-01-19 15:30:28 +03:30
parent 355ec72140
commit 5c3c9739d1

View File

@@ -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<long, RollCall>, 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;