Optimize view of company logos admin page.

This commit is contained in:
2019-05-20 00:59:10 +01:00
parent 6e8eadda17
commit 2a65efab4f
4 changed files with 52 additions and 7 deletions

View File

@@ -24,7 +24,11 @@ namespace cicm_web.Areas.Admin.Controllers
public async Task<IActionResult> Index() public async Task<IActionResult> Index()
{ {
IIncludableQueryable<CompanyLogo, Company> cicmContext = _context.CompanyLogos.Include(c => c.Company); IIncludableQueryable<CompanyLogo, Company> cicmContext = _context.CompanyLogos.Include(c => c.Company);
return View(await cicmContext.OrderBy(l => l.Company.Name).ThenBy(l => l.Year).ToListAsync()); return View(await cicmContext.OrderBy(l => l.Company.Name).ThenBy(l => l.Year)
.Select(l => new CompanyLogoViewModel
{
Company = l.Company.Name, Id = l.Id, Year = l.Year
}).ToListAsync());
} }
// GET: CompanyLogos/Details/5 // GET: CompanyLogos/Details/5
@@ -73,7 +77,8 @@ namespace cicm_web.Areas.Admin.Controllers
CompanyLogo companyLogo = await _context.CompanyLogos.FirstOrDefaultAsync(c => c.Id == id); CompanyLogo companyLogo = await _context.CompanyLogos.FirstOrDefaultAsync(c => c.Id == id);
if(companyLogo == null) return NotFound(); if(companyLogo == null) return NotFound();
ViewData["CompanyId"] = new SelectList(_context.Companies.OrderBy(l => l.Name), "Id", "Name", companyLogo.CompanyId); ViewData["CompanyId"] =
new SelectList(_context.Companies.OrderBy(l => l.Name), "Id", "Name", companyLogo.CompanyId);
return View(companyLogo); return View(companyLogo);
} }
@@ -103,7 +108,8 @@ namespace cicm_web.Areas.Admin.Controllers
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
} }
ViewData["CompanyId"] = new SelectList(_context.Companies.OrderBy(l => l.Name), "Id", "Name", companyLogo.CompanyId); ViewData["CompanyId"] =
new SelectList(_context.Companies.OrderBy(l => l.Name), "Id", "Name", companyLogo.CompanyId);
return View(companyLogo); return View(companyLogo);
} }

View File

@@ -0,0 +1,39 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : CompanyLogo.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ Description ] ----------------------------------------------------------
//
// Describes a company logo and contains the GUID for its file.
//
// --[ 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
*******************************************************************************/
namespace Cicm.Database.Models
{
public class CompanyLogoViewModel
{
public string Company;
public int Id;
public int? Year;
}
}

View File

@@ -1,5 +1,5 @@
@using Cicm.Database.Models @using Cicm.Database.Models
@model IEnumerable<Cicm.Database.Models.CompanyLogo> @model IEnumerable<Cicm.Database.Models.CompanyLogoViewModel>
@{ @{
ViewData["Title"] = "Index"; ViewData["Title"] = "Index";
@@ -27,11 +27,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach(CompanyLogo item in Model) @foreach(CompanyLogoViewModel item in Model)
{ {
<tr> <tr>
<td> <td>
@Html.DisplayFor(modelItem => item.Company.Name) @Html.DisplayFor(modelItem => item.Company)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Year) @Html.DisplayFor(modelItem => item.Year)

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework> <TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.547</Version> <Version>3.0.99.548</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>