From 91e9b04b45d7a17fa5b1edd0fd29580112db2621 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 May 2019 00:24:26 +0100 Subject: [PATCH] Optimize view of resolutions by gpu admin page. --- .../Controllers/ResolutionsByGpuController.cs | 9 +++- .../Admin/Models/ResolutionsByGpuViewModel.cs | 44 +++++++++++++++++++ .../Admin/Views/ResolutionsByGpu/Index.cshtml | 10 ++--- cicm_web/cicm_web.csproj | 2 +- 4 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 cicm_web/Areas/Admin/Models/ResolutionsByGpuViewModel.cs diff --git a/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs b/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs index 13e808e6..a32687e9 100644 --- a/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs +++ b/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs @@ -1,6 +1,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; @@ -28,7 +29,13 @@ namespace cicm_web.Areas.Admin.Controllers return View(await cicmContext.OrderBy(r => r.Gpu.Company.Name).ThenBy(r => r.Gpu.Name) .ThenBy(r => r.Resolution.Chars).ThenBy(r => r.Resolution.Width) .ThenBy(r => r.Resolution.Height).ThenBy(r => r.Resolution.Colors) - .ToListAsync()); + .Select(r => new ResolutionsByGpuViewModel + { + Gpu = r.Gpu.Name, + GpuCompany = r.Gpu.Company.Name, + Id = r.Id, + Resolution = r.Resolution + }).ToListAsync()); } // GET: ResolutionsByGpu/Details/5 diff --git a/cicm_web/Areas/Admin/Models/ResolutionsByGpuViewModel.cs b/cicm_web/Areas/Admin/Models/ResolutionsByGpuViewModel.cs new file mode 100644 index 00000000..9b2f0538 --- /dev/null +++ b/cicm_web/Areas/Admin/Models/ResolutionsByGpuViewModel.cs @@ -0,0 +1,44 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : ResolutionsByGpu.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Junction of resolutions and gpus. +// +// --[ 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; +using Cicm.Database.Models; + +namespace cicm_web.Areas.Admin.Models +{ + public class ResolutionsByGpuViewModel + { + public string GpuCompany; + public long Id; + [DisplayName("GPU")] + public string Gpu { get; set; } + public Resolution Resolution { get; set; } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml index 97323bdb..9dbcd394 100644 --- a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml @@ -1,5 +1,5 @@ -@using Cicm.Database.Models -@model IEnumerable +@using cicm_web.Areas.Admin.Models +@model IEnumerable @{ ViewData["Title"] = "Index"; @@ -26,12 +26,12 @@ - @foreach(ResolutionsByGpu item in Model) + @foreach(ResolutionsByGpuViewModel item in Model) { - @Html.DisplayFor(modelItem => item.Gpu.Company.Name) - @Html.DisplayFor(modelItem => item.Gpu.Name) + @Html.DisplayFor(modelItem => item.GpuCompany) + @Html.DisplayFor(modelItem => item.Gpu) @item.Resolution diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 01eb43eb..5990cf16 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.541 + 3.0.99.542 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website