Move all Blazor code to code-behind files.

This commit is contained in:
2020-05-24 22:10:20 +01:00
parent 08204a1f89
commit 737f69d7da
16 changed files with 307 additions and 259 deletions

View File

@@ -101,55 +101,3 @@
<p>@L["There are no companies in the database."]</p>
}
</p>
@code
{
[Parameter]
public int? CountryId { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
List<CompanyViewModel> _companies;
string _countryName;
char? _character;
protected override async Task OnInitializedAsync()
{
_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);
}
else
CountryId = null;
}
_companies ??= await Service.GetAsync();
}
}

View File

@@ -0,0 +1,60 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Companies
{
public partial class Index
{
char? _character;
List<CompanyViewModel> _companies;
string _countryName;
[Parameter]
public int? CountryId { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
protected override async Task OnInitializedAsync()
{
_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);
}
else
CountryId = null;
}
_companies ??= await Service.GetAsync();
}
}
}

View File

@@ -376,56 +376,3 @@
</div>
}
</div>
@code
{
[Parameter]
public int Id { get; set; }
bool _loaded;
Company _company;
string _carrouselActive;
List<Machine> _computers;
List<Machine> _consoles;
string _description;
Company _soldTo;
public bool ComputersCollapsed { get; set; } = true;
public bool ConsolesCollapsed { get; set; } = true;
protected override async Task OnInitializedAsync()
{
if(Id <= 0)
{
_loaded = true;
return;
}
_company = await Service.GetCompanyAsync(Id);
var machines = await Service.GetMachinesAsync(Id);
_computers = machines.Where(m => m.Type == MachineType.Computer).ToList();
_consoles = machines.Where(m => m.Type == MachineType.Console).ToList();
_description = await Service.GetDescriptionAsync(Id);
_soldTo = await Service.GetSoldToAsync(_company.SoldToId);
_loaded = true;
}
private void CollapseComputers()
{
if (_computers.Count == 0)
return;
ComputersCollapsed = !ComputersCollapsed;
}
private void CollapseConsoles()
{
if (_consoles.Count == 0)
return;
ConsolesCollapsed = !ConsolesCollapsed;
}
}

View File

@@ -0,0 +1,63 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Marechai.Database;
using Marechai.Database.Models;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Companies
{
public partial class View
{
string _carrouselActive;
Company _company;
List<Machine> _computers;
List<Machine> _consoles;
string _description;
bool _loaded;
Company _soldTo;
[Parameter]
public int Id { get; set; }
public bool ComputersCollapsed { get; set; } = true;
public bool ConsolesCollapsed { get; set; } = true;
protected override async Task OnInitializedAsync()
{
if(Id <= 0)
{
_loaded = true;
return;
}
_company = await Service.GetCompanyAsync(Id);
List<Machine> machines = await Service.GetMachinesAsync(Id);
_computers = machines.Where(m => m.Type == MachineType.Computer).ToList();
_consoles = machines.Where(m => m.Type == MachineType.Console).ToList();
_description = await Service.GetDescriptionAsync(Id);
_soldTo = await Service.GetSoldToAsync(_company.SoldToId);
_loaded = true;
}
void CollapseComputers()
{
if(_computers.Count == 0)
return;
ComputersCollapsed = !ComputersCollapsed;
}
void CollapseConsoles()
{
if(_consoles.Count == 0)
return;
ConsolesCollapsed = !ConsolesCollapsed;
}
}
}

View File

@@ -242,20 +242,3 @@
}
}
</p>
@code
{
bool _loaded;
int _computers;
int _minYear;
int _maxYear;
protected override async Task OnInitializedAsync()
{
_computers = await Service.GetComputersCountAsync();
_minYear = await Service.GetMinimumYearAsync();
_maxYear = await Service.GetMaximumYearAsync();
_loaded = true;
}
}

View File

@@ -0,0 +1,21 @@
using System.Threading.Tasks;
namespace Marechai.Pages.Computers
{
public partial class Index
{
int _computers;
bool _loaded;
int _maxYear;
int _minYear;
protected override async Task OnInitializedAsync()
{
_computers = await Service.GetComputersCountAsync();
_minYear = await Service.GetMinimumYearAsync();
_maxYear = await Service.GetMaximumYearAsync();
_loaded = true;
}
}
}

View File

@@ -79,46 +79,3 @@
}
}
</p>
@code
{
[Parameter]
public int? Year { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
List<MachineViewModel> _computers;
char? _character;
protected override async Task OnInitializedAsync()
{
_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)
_computers = await Service.GetComputersByLetterAsync(_character.Value);
if (Year.HasValue &&
_computers is null)
_computers = await Service.GetComputersByYearAsync(Year.Value);
_computers ??= await Service.GetComputersAsync();
}
}

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Computers
{
public partial class Search
{
char? _character;
List<MachineViewModel> _computers;
[Parameter]
public int? Year { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
protected override async Task OnInitializedAsync()
{
_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)
_computers = await Service.GetComputersByLetterAsync(_character.Value);
if(Year.HasValue &&
_computers is null)
_computers = await Service.GetComputersByYearAsync(Year.Value);
_computers ??= await Service.GetComputersAsync();
}
}
}

View File

@@ -242,20 +242,3 @@
}
}
</p>
@code
{
bool _loaded;
int _consoles;
int _minYear;
int _maxYear;
protected override async Task OnInitializedAsync()
{
_consoles = await Service.GetConsolesCountAsync();
_minYear = await Service.GetMinimumYearAsync();
_maxYear = await Service.GetMaximumYearAsync();
_loaded = true;
}
}

View File

@@ -0,0 +1,21 @@
using System.Threading.Tasks;
namespace Marechai.Pages.Consoles
{
public partial class Index
{
int _consoles;
bool _loaded;
int _maxYear;
int _minYear;
protected override async Task OnInitializedAsync()
{
_consoles = await Service.GetConsolesCountAsync();
_minYear = await Service.GetMinimumYearAsync();
_maxYear = await Service.GetMaximumYearAsync();
_loaded = true;
}
}
}

View File

@@ -78,47 +78,4 @@
<p>@L["There are no videogame consoles found introduced this year."]</p>
}
}
</p>
@code
{
[Parameter]
public int? Year { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
List<MachineViewModel> _consoles;
char? _character;
protected override async Task OnInitializedAsync()
{
_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)
_consoles = await Service.GetConsolesByLetterAsync(_character.Value);
if (Year.HasValue &&
_consoles is null)
_consoles = await Service.GetConsolesByYearAsync(Year.Value);
_consoles ??= await Service.GetConsolesAsync();
}
}
</p>

View File

@@ -0,0 +1,50 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Consoles
{
public partial class Search
{
char? _character;
List<MachineViewModel> _consoles;
[Parameter]
public int? Year { get; set; }
[Parameter]
public string StartingCharacter { get; set; }
protected override async Task OnInitializedAsync()
{
_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)
_consoles = await Service.GetConsolesByLetterAsync(_character.Value);
if(Year.HasValue &&
_consoles is null)
_consoles = await Service.GetConsolesByYearAsync(Year.Value);
_consoles ??= await Service.GetConsolesAsync();
}
}
}

View File

@@ -58,13 +58,3 @@
</table>
<br />
}
@code
{
List<NewsViewModel> _news;
protected override void OnInitialized()
{
_news = @Service.GetNews();
}
}

View File

@@ -0,0 +1,12 @@
using System.Collections.Generic;
using Marechai.ViewModels;
namespace Marechai.Pages.Home
{
public partial class Index
{
List<NewsViewModel> _news;
protected override void OnInitialized() => _news = Service.GetNews();
}
}

View File

@@ -876,29 +876,6 @@
<img src="@Path.Combine("/assets/photos/computers", _machine.Id + ".jpg")" alt="">
}
@code
{
[Parameter]
public int Id { get; set; }
MachineViewModel _machine;
bool _loaded;
bool[] _processorVisible;
bool[] _gpuVisible;
bool[] _soundVisible;
protected override async Task OnInitializedAsync()
{
_machine = await Service.GetMachine(Id);
_processorVisible = new bool[_machine.Processors.Count];
_gpuVisible = new bool[_machine.Gpus.Count];
_soundVisible = new bool[_machine.SoundSynthesizers.Count];
_loaded = true;
}
}
<style>
.card {
border: none;

View File

@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using Marechai.ViewModels;
using Microsoft.AspNetCore.Components;
namespace Marechai.Pages.Machines
{
public partial class View
{
bool[] _gpuVisible;
bool _loaded;
MachineViewModel _machine;
bool[] _processorVisible;
bool[] _soundVisible;
[Parameter]
public int Id { get; set; }
protected override async Task OnInitializedAsync()
{
_machine = await Service.GetMachine(Id);
_processorVisible = new bool[_machine.Processors.Count];
_gpuVisible = new bool[_machine.Gpus.Count];
_soundVisible = new bool[_machine.SoundSynthesizers.Count];
_loaded = true;
}
}
}