Skip to content

Commit

Permalink
Merge branch 'main' into add-data-decisions-record
Browse files Browse the repository at this point in the history
  • Loading branch information
aje54 authored Jul 17, 2024
2 parents 723c589 + 34a9585 commit cbb5716
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
1 change: 1 addition & 0 deletions TeachingRecordSystem/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<ItemGroup>
<Using Include="Microsoft.EntityFrameworkCore" />
<Using Include="TeachingRecordSystem.Core" />
<Using Include="TeachingRecordSystem.Core.CoreConstants" Static="true" />
<Using Include="TeachingRecordSystem.Core.Events" />
<Using Include="TeachingRecordSystem.Core.Models" />
<Using Include="System.Threading.Tasks.Task" Alias="Task" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Globalization;

namespace TeachingRecordSystem.Core;

public static class CoreConstants
{
public static readonly CultureInfo EnGbCulture = CultureInfo.GetCultureInfo("en-GB");
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,14 @@
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;

[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; }
Expand Down Expand Up @@ -85,18 +74,18 @@ private async Task<IActionResult> 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);

Expand Down Expand Up @@ -126,7 +115,7 @@ private async Task<IActionResult> 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();
Expand Down

0 comments on commit cbb5716

Please sign in to comment.