Move companies by letter to Blazor.

This commit is contained in:
2020-05-22 00:12:13 +01:00
parent 337dd0b131
commit c430d3e835
7 changed files with 65 additions and 174 deletions

View File

@@ -32,6 +32,7 @@
@page "/companies"
@page "/companies/country/{CountryId:int}"
@page "/companies/{StartingCharacter}"
@inherits OwningComponentBase<CompaniesService>
@inject IStringLocalizer<CompaniesService> L
@inject IWebHostEnvironment Host
@@ -62,6 +63,12 @@
<br />
}
@if (_character.HasValue)
{
<b>@string.Format(L["Companies which name starts with {0}."], _character)</b>
<br />
}
@if (_companies.Any())
{
<p>
@@ -98,20 +105,46 @@
@code
{
[Parameter]
public int? CountryId{get;set;}
public int? CountryId { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
List<CompanyViewModel> _companies;
string _countryName;
char? _character;
protected override async Task OnInitializedAsync()
{
if (CountryId.HasValue)
_character = null;
if (!string.IsNullOrWhiteSpace(StartingCharacter) &&
StartingCharacter.Length == 1)
{
_character = StartingCharacter[0];
// ToUpper()
if (_character >= 'a' &&
_character <= 'z')
_character -= (char)32;
// Check if not letter or number
if (_character < '0' ||
(_character > '9' && _character < 'A') ||
_character > 'Z')
_character = null;
}
if (_character.HasValue)
_companies = await Service.GetCompaniesByLetterAsync(_character.Value);
if (CountryId.HasValue && _companies is null)
{
_countryName = await Service.GetCountryNameAsync(CountryId.Value);
if (_countryName != null)
{
_companies = await Service.GetCompaniesByCountryAsync(CountryId.Value);
_companies = await Service.GetCompaniesByCountryAsync(CountryId.Value);
}
else
CountryId = null;