diff --git a/TeachingRecordSystem/Directory.Build.props b/TeachingRecordSystem/Directory.Build.props index e62115737..86baf3788 100644 --- a/TeachingRecordSystem/Directory.Build.props +++ b/TeachingRecordSystem/Directory.Build.props @@ -14,6 +14,7 @@ + diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.Core/CoreConstants.cs b/TeachingRecordSystem/src/TeachingRecordSystem.Core/CoreConstants.cs new file mode 100644 index 000000000..680e99133 --- /dev/null +++ b/TeachingRecordSystem/src/TeachingRecordSystem.Core/CoreConstants.cs @@ -0,0 +1,8 @@ +using System.Globalization; + +namespace TeachingRecordSystem.Core; + +public static class CoreConstants +{ + public static readonly CultureInfo EnGbCulture = CultureInfo.GetCultureInfo("en-GB"); +} diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Index.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Index.cshtml.cs index 0117ab4ea..b877c2a00 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Index.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Persons/Index.cshtml.cs @@ -9,7 +9,7 @@ namespace TeachingRecordSystem.SupportUi.Pages.Persons; [RedactParameters("Search")] -public partial class IndexModel : PageModel +public partial class IndexModel(TrsLinkGenerator linkGenerator, ICrmQueryDispatcher crmQueryDispatcher) : PageModel { private const int MaxSearchResultCount = 500; private const int PageSize = 15; @@ -17,17 +17,6 @@ public partial class IndexModel : PageModel [GeneratedRegex("^\\d{7}$")] private static partial Regex TrnRegex(); - private readonly TrsLinkGenerator _linkGenerator; - private readonly ICrmQueryDispatcher _crmQueryDispatcher; - - public IndexModel( - TrsLinkGenerator linkGenerator, - ICrmQueryDispatcher crmQueryDispatcher) - { - _linkGenerator = linkGenerator; - _crmQueryDispatcher = crmQueryDispatcher; - } - [BindProperty(SupportsGet = true)] [Display(Name = "Search", Description = "TRN, name or date of birth, for example 4/3/1975")] public string? Search { get; set; } @@ -85,18 +74,18 @@ private async Task PerformSearch() Contact.Fields.dfeta_NINumber); // Check if the search string is a date of birth, TRN or one or more names - if (DateOnly.TryParse(Search, out var dateOfBirth)) + if (DateOnly.TryParse(Search, EnGbCulture, out var dateOfBirth)) { - contacts = await _crmQueryDispatcher.ExecuteQuery(new GetActiveContactsByDateOfBirthQuery(dateOfBirth, SortBy, MaxSearchResultCount, columnSet)); + contacts = await crmQueryDispatcher.ExecuteQuery(new GetActiveContactsByDateOfBirthQuery(dateOfBirth, SortBy, MaxSearchResultCount, columnSet)); } else if (TrnRegex().IsMatch(Search!)) { - var contact = await _crmQueryDispatcher.ExecuteQuery(new GetActiveContactByTrnQuery(Search!, columnSet)); + var contact = await crmQueryDispatcher.ExecuteQuery(new GetActiveContactByTrnQuery(Search!, columnSet)); contacts = contact is not null ? [contact] : []; } else { - contacts = await _crmQueryDispatcher.ExecuteQuery(new GetActiveContactsByNameQuery(Search!, SortBy, MaxSearchResultCount, columnSet)); + contacts = await crmQueryDispatcher.ExecuteQuery(new GetActiveContactsByNameQuery(Search!, SortBy, MaxSearchResultCount, columnSet)); } Debug.Assert(contacts is not null); @@ -126,7 +115,7 @@ private async Task PerformSearch() // if the page number is greater than the total number of pages, redirect to the first page if (PageNumber > TotalKnownPages) { - return Redirect(_linkGenerator.Persons(search: Search)); + return Redirect(linkGenerator.Persons(search: Search)); } return Page();