mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Optimize view of machines admin page.
This commit is contained in:
@@ -33,6 +33,7 @@ using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Cicm.Database;
|
||||
using Cicm.Database.Models;
|
||||
using cicm_web.Areas.Admin.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
@@ -57,8 +58,17 @@ namespace cicm_web.Areas.Admin.Controllers
|
||||
{
|
||||
IIncludableQueryable<Machine, MachineFamily> cicmContext =
|
||||
_context.Machines.Include(m => m.Company).Include(m => m.Family);
|
||||
return View(await cicmContext.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).ThenBy(m => m.Family)
|
||||
.ToListAsync());
|
||||
return View(await cicmContext.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).ThenBy(m => m.Family.Name)
|
||||
.Select(m => new MachineViewModel
|
||||
{
|
||||
Id = m.Id,
|
||||
Company = m.Company.Name,
|
||||
Name = m.Name,
|
||||
Model = m.Model,
|
||||
Introduced = m.Introduced,
|
||||
Type = m.Type,
|
||||
Family = m.Family.Name
|
||||
}).ToListAsync());
|
||||
}
|
||||
|
||||
// GET: Admin/Machines/Details/5
|
||||
|
||||
27
cicm_web/Areas/Admin/Models/MachineViewModel.cs
Normal file
27
cicm_web/Areas/Admin/Models/MachineViewModel.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Cicm.Database;
|
||||
|
||||
namespace cicm_web.Areas.Admin.Models
|
||||
{
|
||||
public class MachineViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[StringLength(255)]
|
||||
public string Name { get; set; }
|
||||
public MachineType Type { get; set; }
|
||||
[DisplayFormat(DataFormatString = "{0:d}")]
|
||||
[DataType(DataType.Date)]
|
||||
public DateTime? Introduced { get; set; }
|
||||
public string Family { get; set; }
|
||||
[StringLength(50)]
|
||||
public string Model { get; set; }
|
||||
|
||||
public string Company { get; set; }
|
||||
|
||||
[DisplayName("Introduced")]
|
||||
public string IntroducedView =>
|
||||
Introduced == DateTime.MinValue ? "Prototype" : Introduced?.ToShortDateString() ?? "Unknown";
|
||||
}
|
||||
}
|
||||
@@ -29,8 +29,8 @@
|
||||
// Copyright © 2003-2018 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
}
|
||||
@using Cicm.Database.Models
|
||||
@model IEnumerable<Cicm.Database.Models.Machine>
|
||||
@using cicm_web.Areas.Admin.Models
|
||||
@model IEnumerable<cicm_web.Areas.Admin.Models.MachineViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Machines (Admin)";
|
||||
@@ -69,14 +69,14 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach(Machine item in Model)
|
||||
@foreach(MachineViewModel item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Company.Name)
|
||||
@Html.DisplayFor(modelItem => item.Company)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Family.Name)
|
||||
@Html.DisplayFor(modelItem => item.Family)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Name)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||
<Version>3.0.99.537</Version>
|
||||
<Version>3.0.99.538</Version>
|
||||
<Company>Canary Islands Computer Museum</Company>
|
||||
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
|
||||
<Product>Canary Islands Computer Museum Website</Product>
|
||||
|
||||
Reference in New Issue
Block a user