diff --git a/Marechai/Controllers/CompanyController.cs b/Marechai/Controllers/CompanyController.cs deleted file mode 100644 index 2e8c38a4..00000000 --- a/Marechai/Controllers/CompanyController.cs +++ /dev/null @@ -1,88 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : CompanyController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Company 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.Models; -using Marechai.ViewModels; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace Marechai.Controllers -{ - public class CompanyController : Controller - { - readonly MarechaiContext _context; - readonly IWebHostEnvironment hostingEnvironment; - - public CompanyController(IWebHostEnvironment env, MarechaiContext context) - { - hostingEnvironment = env; - _context = context; - } - - 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; - - ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - - if(id == '\0') - return RedirectToAction(nameof(Index)); - - return View(_context.Companies.Include(c => c.Logos).Where(c => c.Name.StartsWith(id)).OrderBy(c => c.Name). - Select(c => new CompanyViewModel - { - Id = c.Id, LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid, - Name = c.Name - }).ToList()); - } - - public IActionResult Index() - { - ViewBag.WebRootPath = hostingEnvironment.WebRootPath; - - return View(_context.Companies.Include(c => c.Logos).OrderBy(c => c.Name).Select(c => new CompanyViewModel - { - Id = c.Id, LastLogo = c.Logos.OrderByDescending(l => l.Year).FirstOrDefault().Guid, Name = c.Name - }).ToList()); - } - } -} \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index fe95f344..f783813f 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.954 + 3.0.99.961 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website diff --git a/Marechai/Pages/Companies/Index.razor b/Marechai/Pages/Companies/Index.razor index e938df95..56c6d336 100644 --- a/Marechai/Pages/Companies/Index.razor +++ b/Marechai/Pages/Companies/Index.razor @@ -32,6 +32,7 @@ @page "/companies" @page "/companies/country/{CountryId:int}" +@page "/companies/{StartingCharacter}" @inherits OwningComponentBase @inject IStringLocalizer L @inject IWebHostEnvironment Host @@ -62,6 +63,12 @@
} + @if (_character.HasValue) + { + @string.Format(L["Companies which name starts with {0}."], _character) +
+ } + @if (_companies.Any()) {

@@ -98,20 +105,46 @@ @code { [Parameter] - public int? CountryId{get;set;} + public int? CountryId { get; set; } + + [Parameter] + public string StartingCharacter { get; set; } List _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; diff --git a/Marechai/Pages/Companies/View.razor b/Marechai/Pages/Companies/View.razor index 37b5df0d..d16dd418 100644 --- a/Marechai/Pages/Companies/View.razor +++ b/Marechai/Pages/Companies/View.razor @@ -30,7 +30,7 @@ *******************************************************************************/ } -@page "/companies/{Id:int}" +@page "/company/{Id:int}" @using Marechai.Database.Models @using Marechai.Database @@ -159,7 +159,7 @@ if (_soldTo != null) { - + @string.Format(L["Company sold to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString()) } @@ -173,7 +173,7 @@ if (_soldTo != null) { - + @string.Format(L["Company sold to {0} on an unknown date."], _soldTo.Name) } @@ -189,7 +189,7 @@ if (_soldTo != null) { - @string.Format(L["Company merged on {0} to form {1}."], _company.Sold.Value.ToLongDateString(), _soldTo.Name) + @string.Format(L["Company merged on {0} to form {1}."], _company.Sold.Value.ToLongDateString(), _soldTo.Name) } else @@ -202,7 +202,7 @@ if (_soldTo != null) { - @string.Format(L["Company merged on an unknown date to form {0}."], _soldTo.Name) + @string.Format(L["Company merged on an unknown date to form {0}."], _soldTo.Name) } else @@ -237,7 +237,7 @@ if (_soldTo != null) { - @string.Format(L["Company renamed to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString()) + @string.Format(L["Company renamed to {0} on {1}."], _soldTo.Name, _company.Sold.Value.ToLongDateString()) } else @@ -250,7 +250,7 @@ if (_soldTo != null) { - + @string.Format(L["Company renamed to {0} on an unknown date."], _soldTo.Name) } diff --git a/Marechai/Resources/Services/CompaniesService.es.resx b/Marechai/Resources/Services/CompaniesService.es.resx index 8e94a0f4..ba989cd5 100644 --- a/Marechai/Resources/Services/CompaniesService.es.resx +++ b/Marechai/Resources/Services/CompaniesService.es.resx @@ -250,4 +250,8 @@ Compañías fundadas en {0}. Companies founded in, {0} country name + + Compañías cuyo nombre empieza por {0}. + Companies with {0}, a single character, as the start of the name + \ No newline at end of file diff --git a/Marechai/Services/CompaniesService.cs b/Marechai/Services/CompaniesService.cs index 2a606fd5..4f85ee11 100644 --- a/Marechai/Services/CompaniesService.cs +++ b/Marechai/Services/CompaniesService.cs @@ -103,5 +103,22 @@ namespace Marechai.Services Guid, Name = c.Name }).ToListAsync(); + + public Task> GetCompaniesByLetterAsync(char id) => _context. + Companies.Include(c => c.Logos). + Where(c => EF.Functions.Like(c.Name, + $"{id}%")). + OrderBy(c => c.Name). + Select(c => new CompanyViewModel + { + Id = c.Id, + LastLogo = c. + Logos. + OrderByDescending(l => + l. + Year). + FirstOrDefault().Guid, + Name = c.Name + }).ToListAsync(); } } \ No newline at end of file diff --git a/Marechai/Views/Company/ByLetter.cshtml b/Marechai/Views/Company/ByLetter.cshtml deleted file mode 100644 index 2675e0df..00000000 --- a/Marechai/Views/Company/ByLetter.cshtml +++ /dev/null @@ -1,75 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ByLetter.cshtml -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Lists companies 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"] = "Companies"; -} -@using System.IO -@model IEnumerable -

Search results:

-

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

- @Model.Count() companies found in the database. -
- @foreach (var company in Model) - { - - @if (company.LastLogo != null && - File.Exists(System.IO.Path.Combine(ViewBag.WebRootPath, "assets/logos", company.LastLogo + ".svg"))) - { - - - - - - } - @company.Name - -
- } -

- } - else - { -

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

- } -

\ No newline at end of file