Add search computer by year.

This commit is contained in:
2018-04-14 05:49:11 +01:00
parent 113cebe789
commit 8ddeeeaf4e
4 changed files with 76 additions and 2 deletions

View File

@@ -34,5 +34,12 @@ namespace cicm_web.Controllers
return View(computers); return View(computers);
} }
public IActionResult ByYear(int id)
{
ViewBag.Year = id;
return View(ComputerMini.GetItemsFromYear(id));
}
} }
} }

View File

@@ -182,9 +182,22 @@ namespace cicm_web.Models
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray(); return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
} }
public static ComputerMini[] GetItemsFromYear(int year)
{
List<Cicm.Database.Schemas.Computer> dbItems = null;
bool? result = Program.Database?.Operations.GetComputers(out dbItems);
if(result == null || result.Value == false || dbItems == null) return null;
List<ComputerMini> items = new List<ComputerMini>();
foreach(Cicm.Database.Schemas.Computer dbItem in dbItems)
if(dbItem.Year == year)
items.Add(TransformItem(dbItem));
return items.OrderBy(t => t.Company.Name).ThenBy(t => t.Model).ToArray();
}
static ComputerMini TransformItem(Cicm.Database.Schemas.Computer dbItem) static ComputerMini TransformItem(Cicm.Database.Schemas.Computer dbItem)
{ {
System.Console.WriteLine("Transforming item");
return new ComputerMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model}; return new ComputerMini {Company = Company.GetItem(dbItem.Company), Id = dbItem.Id, Model = dbItem.Model};
} }
} }

View File

@@ -0,0 +1,54 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : ByLetter.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
ViewData["Title"] = "Computers";
}
@model IEnumerable<ComputerMini>
<p>Search results:</p>
<p align="center">
<b>@ViewBag.Year</b><br/>
@if(Model.Any())
{
<p>@Model.Count() computers found in the database.<br />
@foreach(ComputerMini computer in @Model)
{
<a asp-controller="Computer" asp-action="View" asp-route-id="@computer.Id">@computer.Company.Name @computer.Model</a><br/>
}
</p>
}
else
{
<p>There are no computers found in the database released this year.</p>
}
</p>

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<Version>3.0.99.67</Version> <Version>3.0.99.68</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>