diff --git a/Marechai.sln.DotSettings b/Marechai.sln.DotSettings index 9333e267..9ec04b4a 100644 --- a/Marechai.sln.DotSettings +++ b/Marechai.sln.DotSettings @@ -1,2 +1,3 @@  - True \ No newline at end of file + True + True \ No newline at end of file diff --git a/Marechai/Controllers/ConsoleController.cs b/Marechai/Controllers/ConsoleController.cs deleted file mode 100644 index 49332bd8..00000000 --- a/Marechai/Controllers/ConsoleController.cs +++ /dev/null @@ -1,100 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ConsoleController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Videogame console controller -// -// --[ License ] -------------------------------------------------------------- -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ - -using System.Linq; -using Marechai.Database; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; - -namespace Marechai.Controllers -{ - public class ConsoleController : Controller - { - readonly MarechaiContext _context; - readonly IWebHostEnvironment hostingEnvironment; - - public ConsoleController(IWebHostEnvironment env, MarechaiContext context) - { - hostingEnvironment = env; - _context = context; - } - - public IActionResult Index() - { - ViewBag.ItemCount = _context.Machines.Count(m => m.Type == MachineType.Console); - - ViewBag.MinYear = _context. - Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue && - t.Introduced.Value.Year > 1000).Min(t => t.Introduced.Value.Year); - - ViewBag.MaxYear = _context. - Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue && - t.Introduced.Value.Year > 1000).Max(t => t.Introduced.Value.Year); - - return View(); - } - - public IActionResult ByLetter(char id) - { - // ToUpper() - if(id >= 'a' && - id <= 'z') - id -= (char)32; - - // Check if not letter - if(id < 'A' || - id > 'Z') - id = '\0'; - - ViewBag.Letter = id; - - return View(id == '\0' ? _context.Machines.Where(m => m.Type == MachineType.Console).ToArray() : _context. - Machines. - Where(m => - m. - Type == - MachineType. - Console && - m. - Name. - StartsWith(id)). - ToArray()); - } - - public IActionResult ByYear(int id) - { - ViewBag.Year = id; - - return View(_context.Machines.Where(t => t.Type == MachineType.Console && t.Introduced.HasValue && - t.Introduced.Value.Year == id).ToArray()); - } - } -} \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 9ad3b898..a7cce348 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.965 + 3.0.99.966 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Computers/Index.razor b/Marechai/Pages/Computers/Index.razor index faf82056..ec4de0d2 100644 --- a/Marechai/Pages/Computers/Index.razor +++ b/Marechai/Pages/Computers/Index.razor @@ -42,7 +42,7 @@

@L["Here you can consult our database."]
- @L["In this database you can find technical information as well as computers history, catalogued by companies, alfabetically and by release date."] + @L["In this database you can find technical information as well as computers history, catalogued by companies, alphabetically and by release date."]
@string.Format(L["{0} computers actually catalogued in the database."], _computers)

diff --git a/Marechai/Pages/Consoles/Index.razor b/Marechai/Pages/Consoles/Index.razor new file mode 100644 index 00000000..abfa8564 --- /dev/null +++ b/Marechai/Pages/Consoles/Index.razor @@ -0,0 +1,261 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : Index.razor +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Consoles index +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ +} + +@page "/consoles" +@inherits OwningComponentBase +@inject IStringLocalizer L + +@if (!_loaded) +{ + @L["Loading..."] +} + +

+ @L["Here you can consult our database."] +
+ @L["In this database you can find technical information as well as videogame consoles history, catalogued by companies, alphabetically and by release date."] +
+ @string.Format(L["{0} videogame consoles actually catalogued in the database."], _consoles) +

+

+
+
+ @L["Search by companies"] +
+ + Q + + + W + + + E + + + R + + + T + + + Y + + + U + + + I + + + O + + + P + +
+ + A + + + S + + + D + + + F + + + G + + + H + + + J + + + K + + + L + +
+ + Z + + + X + + + C + + + V + + + B + + + N + + + M + +
+ + @L["All companies"] + +

+

+ @L["Alphabetically search"] +
+ + Q + + + W + + + E + + + R + + + T + + + Y + + + U + + + I + + + O + + + P + +
+ + A + + + S + + + D + + + F + + + G + + + H + + + J + + + K + + + L + +
+ + Z + + + X + + + C + + + V + + + B + + + N + + + M + +
+ + @L["All videogame consoles"] + +

+

+ @L["Search by year"] +
+ @{ var counter = 0; } + @for (int i = _minYear; i <= _maxYear; i++) + { + { + counter++; + } + + @i + + if (counter % 8 == 0) + { +
+ } + } +

+ +@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; + } +} diff --git a/Marechai/Pages/Consoles/Search.razor b/Marechai/Pages/Consoles/Search.razor new file mode 100644 index 00000000..e0336a89 --- /dev/null +++ b/Marechai/Pages/Consoles/Search.razor @@ -0,0 +1,124 @@ +@{ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : Search.razor +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Consoles search +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ +} + +@page "/consoles/all" +@page "/consoles/year/{Year:int}" +@page "/consoles/{StartingCharacter}" +@inherits OwningComponentBase +@inject IStringLocalizer L + +@if (_consoles is null) +{ + @L["Loading..."] +} + +

@L["Search results:"]

+

+ @if (_character.HasValue) + { + @string.Format(L["Videogame consoles starting with {0}"], _character) +
+ } + else if (Year.HasValue) + { + @string.Format(L["Videogame consoles introduced in {0}"], Year) +
+ } + + @if (_consoles?.Count > 0) + { +

+ @string.Format(L["{0} videogame consoles found in the database."], _consoles.Count) +
+ @foreach (var console in _consoles) + { + + @console.CompanyName @console.Name +
+ } +

+ } + else + { + @if (_character.HasValue) + { +

@L["There are no videogame consoles found in the database that start with this letter."]

+ } + else if (Year.HasValue) + { +

@L["There are no videogame consoles found introduced this year."]

+ } + } +

+ +@code +{ + [Parameter] + public int? Year { get; set; } + + [Parameter] + public string StartingCharacter { get; set; } + + List _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(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/ComputersService.es.resx b/Marechai/Resources/Services/ComputersService.es.resx index a6f17039..c6f3b68f 100644 --- a/Marechai/Resources/Services/ComputersService.es.resx +++ b/Marechai/Resources/Services/ComputersService.es.resx @@ -126,7 +126,7 @@ Aquí puedes consultar nuestra base de datos. Introduction to search - + En esta base de datos puedes encontrar información técnica así como historia de los ordenadores, catalogados por compañía, alfabéticamente y por fecha de introducción. Introduction to database diff --git a/Marechai/Resources/Services/ConsolesService.es.resx b/Marechai/Resources/Services/ConsolesService.es.resx new file mode 100644 index 00000000..1371c2d2 --- /dev/null +++ b/Marechai/Resources/Services/ConsolesService.es.resx @@ -0,0 +1,181 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cargando... + Message that appears while data is being loaded from database + + + Aquí puedes consultar nuestra base de datos. + Introduction to search + + + En esta base de datos puedes encontrar información técnica así como historia de los videoconsolas, catalogados por compañía, alfabéticamente y por fecha de introducción. + Introduction to database + + + {0} videoconsolas catalogados en la base de datos + Consoles in database, {0} number + + + Buscar por compañías + Search by companies + + + Todas las compañías + All companies + + + Búsqueda alfabética + Search alphabetically + + + Todas las videoconsolas + All consoles + + + Búsqueda por año + Search by year + + + Resultados: + Search results + + + Videoconsolas cuyo nombre comienza por {0} + Consoles starting with {0}, a letter + + + Videoconsolas introducidas en {0} + Consoles introduced in, {0} is a year + + + {0} videoconsolas en la base de datos + Consoles found by search, {0} is number + + + No se encontraron videoconsolas en la base de datos cuyo nombre comience por esa letra. + No consoles in DB with that letter + + + No se encontraron videoconsolas en la base de datos introducidos en ese año. + No consoles in DB from that year + + \ No newline at end of file diff --git a/Marechai/Services/ConsolesService.cs b/Marechai/Services/ConsolesService.cs new file mode 100644 index 00000000..9b8ff091 --- /dev/null +++ b/Marechai/Services/ConsolesService.cs @@ -0,0 +1,92 @@ +/****************************************************************************** +// MARECHAI: Master repository of computing history artifacts information +// ---------------------------------------------------------------------------- +// +// Filename : ConsolesService.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Consoles service +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2020 Natalia Portillo +*******************************************************************************/ + +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marechai.Database; +using Marechai.Database.Models; +using Marechai.ViewModels; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Localization; + +namespace Marechai.Services +{ + public class ConsolesService + { + readonly MarechaiContext _context; + readonly IStringLocalizer _l; + + public ConsolesService(MarechaiContext context, IStringLocalizer localizer) + { + _context = context; + _l = localizer; + } + + public async Task GetConsolesCountAsync() => + await _context.Machines.CountAsync(c => c.Type == MachineType.Console); + + public Task GetMinimumYearAsync() => _context. + Machines.Where(t => t.Type == MachineType.Console && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000). + MinAsync(t => t.Introduced.Value.Year); + + public Task GetMaximumYearAsync() => _context. + Machines.Where(t => t.Type == MachineType.Console && + t.Introduced.HasValue && + t.Introduced.Value.Year > 1000). + MaxAsync(t => t.Introduced.Value.Year); + + public async Task> GetConsolesByLetterAsync(char c) => + await _context.Machines.Include(m => m.Company). + Where(m => m.Type == MachineType.Console && EF.Functions.Like(m.Name, $"{c}%")). + OrderBy(m => m.Company.Name).ThenBy(m => m.Name).Select(m => new MachineViewModel + { + Id = m.Id, Name = m.Name, CompanyName = m.Company.Name + }).ToListAsync(); + + public async Task> GetConsolesByYearAsync(int year) => + await _context.Machines.Include(m => m.Company). + Where(m => m.Type == MachineType.Console && m.Introduced != null && + m.Introduced.Value.Year == year).OrderBy(m => m.Company.Name).ThenBy(m => m.Name). + Select(m => new MachineViewModel + { + Id = m.Id, Name = m.Name, CompanyName = m.Company.Name + }).ToListAsync(); + + public async Task> GetConsolesAsync() => + await _context.Machines.Include(m => m.Company).Where(m => m.Type == MachineType.Console). + OrderBy(m => m.Company.Name).ThenBy(m => m.Name).Select(m => new MachineViewModel + { + Id = m.Id, Name = m.Name, CompanyName = m.Company.Name + }).ToListAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index c6c70fe6..fed4aa62 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -44,6 +44,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/Views/Console/ByLetter.cshtml b/Marechai/Views/Console/ByLetter.cshtml deleted file mode 100644 index b88baa30..00000000 --- a/Marechai/Views/Console/ByLetter.cshtml +++ /dev/null @@ -1,60 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ByLetter.cshtml -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Lists computers by letter (or all) -// -// --[ License ] -------------------------------------------------------------- -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ - - ViewData["Title"] = "Consoles"; -} -@model Marechai.Database.Models.Machine[] -

Search results:

-

- @if (ViewBag.Letter != '\0') - { - @ViewBag.Letter -
- } - - @if (Model.Any()) - { -

- @Model.Count() computers found in the database. -
- @foreach (var console in Model) - { - - @console.Company.Name @console.Name -
- } -

- } - else - { -

There are no videoconsoles found in the database that start with this letter.

- } -

\ No newline at end of file diff --git a/Marechai/Views/Console/ByYear.cshtml b/Marechai/Views/Console/ByYear.cshtml deleted file mode 100644 index 589fa792..00000000 --- a/Marechai/Views/Console/ByYear.cshtml +++ /dev/null @@ -1,56 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ByYear.cshtml -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Lists computers by letter (or all) -// -// --[ License ] -------------------------------------------------------------- -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ - - ViewData["Title"] = "Computers"; -} -@model Marechai.Database.Models.Machine[] -

Search results:

-

- @ViewBag.Year -
- @if (Model.Any()) - { -

- @Model.Count() videoconsoles found in the database. -
- @foreach (var console in Model) - { - - @console.Company.Name @console.Name -
- } -

- } - else - { -

There are no videoconsoles found in the database released this year.

- } -

\ No newline at end of file diff --git a/Marechai/Views/Console/Index.cshtml b/Marechai/Views/Console/Index.cshtml deleted file mode 100644 index e512d9cd..00000000 --- a/Marechai/Views/Console/Index.cshtml +++ /dev/null @@ -1,236 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : Contact.cshtml -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Contact page -// -// --[ License ] -------------------------------------------------------------- -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as -// published by the Free Software Foundation, either version 3 of the -// License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . -// -// ---------------------------------------------------------------------------- -// Copyright © 2003-2020 Natalia Portillo -*******************************************************************************/ - - ViewData["Title"] = "Videoconsoles"; -} -

- Here you can consult our database. -
- In this database you can find technical information as well as videoconsoles history, catalogued by companies, alfabetically and by release date. -
- @ViewBag.ItemCount videoconsoles actually catalogued in the database. -

-

-
-
- Search by companies -
- - Q - - - W - - - E - - - R - - - T - - - Y - - - U - - - I - - - O - - - P - -
- - A - - - S - - - D - - - F - - - G - - - H - - - J - - - K - - - L - -
- - Z - - - X - - - C - - - V - - - B - - - N - - - M - -
- - All companies - -

-

- Alfabetically search -
- - Q - - - W - - - E - - - R - - - T - - - Y - - - U - - - I - - - O - - - P - -
- - A - - - S - - - D - - - F - - - G - - - H - - - J - - - K - - - L - -
- - Z - - - X - - - C - - - V - - - B - - - N - - - M - -
- - All consoles - -

-

- Search by year -
- @{ var counter = 0; } - @for (int i = ViewBag.MinYear; i <= ViewBag.MaxYear; i++) - { - { - counter++; - } - - @i - - if (counter % 8 == 0) - { -
- } - } -

\ No newline at end of file