From a51f93ea201c7ed0c1d7c46a5e116bc9242f5614 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 20 May 2019 00:30:14 +0100 Subject: [PATCH] Optimize view of sound synthetizers admin page. --- .../Controllers/SoundSynthsController.cs | 11 +++- .../Areas/Admin/Models/SoundSynthViewModel.cs | 56 +++++++++++++++++++ .../Admin/Views/SoundSynths/Index.cshtml | 6 +- cicm_web/cicm_web.csproj | 2 +- 4 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 cicm_web/Areas/Admin/Models/SoundSynthViewModel.cs diff --git a/cicm_web/Areas/Admin/Controllers/SoundSynthsController.cs b/cicm_web/Areas/Admin/Controllers/SoundSynthsController.cs index 545496f0..ea3972bc 100644 --- a/cicm_web/Areas/Admin/Controllers/SoundSynthsController.cs +++ b/cicm_web/Areas/Admin/Controllers/SoundSynthsController.cs @@ -54,7 +54,16 @@ namespace cicm_web.Areas.Admin.Controllers public async Task Index() { IIncludableQueryable cicmContext = _context.SoundSynths.Include(s => s.Company); - return View(await cicmContext.ToListAsync()); + return View(await cicmContext.OrderBy(s => s.Company).ThenBy(s => s.Name).ThenBy(s => s.ModelCode) + .Select(s => new SoundSynthViewModel + { + Company = s.Company.Name, + Id = s.Id, + Introduced = s.Introduced, + ModelCode = s.ModelCode, + Name = s.Name, + Type = s.Type + }).ToListAsync()); } // GET: Admin/SoundSynths/Details/5 diff --git a/cicm_web/Areas/Admin/Models/SoundSynthViewModel.cs b/cicm_web/Areas/Admin/Models/SoundSynthViewModel.cs new file mode 100644 index 00000000..da6f3b96 --- /dev/null +++ b/cicm_web/Areas/Admin/Models/SoundSynthViewModel.cs @@ -0,0 +1,56 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : SoundSynth.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Describes chips that generate sound. +// +// --[ 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; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Cicm.Database.Models +{ + public class SoundSynthViewModel + + { + public int Id; + + public string Name { get; set; } + [DisplayName("Model code")] + public string ModelCode { get; set; } + [DisplayFormat(DataFormatString = "{0:d}")] + [DataType(DataType.Date)] + public DateTime? Introduced { get; set; } + public int? Type { get; set; } + + public string Company { get; set; } + + [NotMapped] + public string IntroducedView => Introduced?.ToShortDateString() ?? "Unknown"; + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/SoundSynths/Index.cshtml b/cicm_web/Areas/Admin/Views/SoundSynths/Index.cshtml index 57f5129d..ec73f2a5 100644 --- a/cicm_web/Areas/Admin/Views/SoundSynths/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/SoundSynths/Index.cshtml @@ -30,7 +30,7 @@ *******************************************************************************/ } @using Cicm.Database.Models -@model IEnumerable +@model IEnumerable @{ ViewData["Title"] = "Sound synthetizers (Admin)"; @@ -66,11 +66,11 @@ - @foreach(SoundSynth item in Model) + @foreach(SoundSynthViewModel item in Model) { - @Html.DisplayFor(modelItem => item.Company.Name) + @Html.DisplayFor(modelItem => item.Company) @Html.DisplayFor(modelItem => item.Name) diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 5990cf16..da2f6c1f 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.542 + 3.0.99.543 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website