From 1760e98da282758fb56f8a3aa9941ff05a7b3a9b Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 May 2019 00:07:00 +0100 Subject: [PATCH] Optimize view of processors by machine admin page. --- .../ProcessorsByMachinesController.cs | 10 ++++- ...Machine.cs => MemoryByMachineViewModel.cs} | 0 .../Models/ProcessorsByMachineViewModel.cs | 43 +++++++++++++++++++ .../Views/ProcessorsByMachines/Index.cshtml | 10 ++--- cicm_web/cicm_web.csproj | 2 +- 5 files changed, 58 insertions(+), 7 deletions(-) rename cicm_web/Areas/Admin/Models/{MemoryByMachine.cs => MemoryByMachineViewModel.cs} (100%) create mode 100644 cicm_web/Areas/Admin/Models/ProcessorsByMachineViewModel.cs diff --git a/cicm_web/Areas/Admin/Controllers/ProcessorsByMachinesController.cs b/cicm_web/Areas/Admin/Controllers/ProcessorsByMachinesController.cs index 07cb9a1c..7714f183 100644 --- a/cicm_web/Areas/Admin/Controllers/ProcessorsByMachinesController.cs +++ b/cicm_web/Areas/Admin/Controllers/ProcessorsByMachinesController.cs @@ -31,6 +31,7 @@ using System.Linq; using System.Threading.Tasks; using Cicm.Database.Models; +using cicm_web.Areas.Admin.Models; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; @@ -55,7 +56,14 @@ namespace cicm_web.Areas.Admin.Controllers { IIncludableQueryable cicmContext = _context.ProcessorsByMachine.Include(p => p.Machine).Include(p => p.Processor); - return View(await cicmContext.OrderBy(p => p.Machine.Name).ThenBy(p => p.Processor.Name).ToListAsync()); + return View(await cicmContext.OrderBy(p => p.Machine.Name).ThenBy(p => p.Processor.Name) + .Select(p => new ProcessorsByMachineViewModel + { + Id = p.Id, + Machine = p.Machine.Name, + Processor = p.Processor.Name, + Speed = p.Speed + }).ToListAsync()); } // GET: Admin/ProcessorsByMachines/Details/5 diff --git a/cicm_web/Areas/Admin/Models/MemoryByMachine.cs b/cicm_web/Areas/Admin/Models/MemoryByMachineViewModel.cs similarity index 100% rename from cicm_web/Areas/Admin/Models/MemoryByMachine.cs rename to cicm_web/Areas/Admin/Models/MemoryByMachineViewModel.cs diff --git a/cicm_web/Areas/Admin/Models/ProcessorsByMachineViewModel.cs b/cicm_web/Areas/Admin/Models/ProcessorsByMachineViewModel.cs new file mode 100644 index 00000000..0a731198 --- /dev/null +++ b/cicm_web/Areas/Admin/Models/ProcessorsByMachineViewModel.cs @@ -0,0 +1,43 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : ProcessorByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Junction of processor and machine. +// +// --[ 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-2018 Natalia Portillo +*******************************************************************************/ + +using System.ComponentModel; + +namespace cicm_web.Areas.Admin.Models +{ + public class ProcessorsByMachineViewModel + { + public long Id { get; set; } + public string Processor { get; set; } + public string Machine { get; set; } + [DisplayName("Speed (MHz)")] + public float? Speed { get; set; } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByMachines/Index.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByMachines/Index.cshtml index 1882dd5e..8748d8f4 100644 --- a/cicm_web/Areas/Admin/Views/ProcessorsByMachines/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/ProcessorsByMachines/Index.cshtml @@ -29,8 +29,8 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ } -@using Cicm.Database.Models -@model IEnumerable +@using cicm_web.Areas.Admin.Models +@model IEnumerable @{ ViewData["Title"] = "Processors by machine (Admin)"; @@ -60,14 +60,14 @@ - @foreach(ProcessorsByMachine item in Model) + @foreach(ProcessorsByMachineViewModel item in Model) { - @Html.DisplayFor(modelItem => item.Machine.Name) + @Html.DisplayFor(modelItem => item.Machine) - @Html.DisplayFor(modelItem => item.Processor.Name) + @Html.DisplayFor(modelItem => item.Processor) @Html.DisplayFor(modelItem => item.Speed) diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index d81e2e2f..952a870e 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.539 + 3.0.99.540 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website