Sort machines in admin page.

This commit is contained in:
2019-05-18 21:47:50 +01:00
parent d1082cc4b9
commit b916bcedfa
8 changed files with 136 additions and 103 deletions

View File

@@ -30,6 +30,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
namespace Cicm.Database.Models namespace Cicm.Database.Models
{ {
@@ -59,5 +61,10 @@ namespace Cicm.Database.Models
public virtual ICollection<ProcessorsByMachine> Processors { get; set; } public virtual ICollection<ProcessorsByMachine> Processors { get; set; }
public virtual ICollection<SoundByMachine> Sound { get; set; } public virtual ICollection<SoundByMachine> Sound { get; set; }
public virtual ICollection<StorageByMachine> Storage { get; set; } public virtual ICollection<StorageByMachine> Storage { get; set; }
[NotMapped]
[DisplayName("Introduced")]
public string IntroducedView =>
Introduced == DateTime.MinValue ? "Prototype" : Introduced?.ToShortDateString() ?? "Unknown";
} }
} }

View File

@@ -55,7 +55,8 @@ namespace cicm_web.Areas.Admin.Controllers
{ {
IIncludableQueryable<Machine, MachineFamily> cicmContext = IIncludableQueryable<Machine, MachineFamily> cicmContext =
_context.Machines.Include(m => m.Company).Include(m => m.Family); _context.Machines.Include(m => m.Company).Include(m => m.Family);
return View(await cicmContext.ToListAsync()); return View(await cicmContext.OrderBy(m => m.Company.Name).ThenBy(m => m.Name).ThenBy(m => m.Family)
.ToListAsync());
} }
// GET: Admin/Machines/Details/5 // GET: Admin/Machines/Details/5

View File

@@ -29,6 +29,7 @@
// Copyright © 2003-2018 Natalia Portillo // Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
} }
@using Cicm.Database
@model Cicm.Database.Models.Machine @model Cicm.Database.Models.Machine
@{ @{
@@ -45,6 +46,24 @@
<div asp-validation-summary="ModelOnly" <div asp-validation-summary="ModelOnly"
class="text-danger"> class="text-danger">
</div> </div>
<div class="form-group">
<label asp-for="Company"
class="control-label">
</label>
<select asp-for="CompanyId"
class="form-control"
asp-items="ViewBag.CompanyId">
</select>
</div>
<div class="form-group">
<label asp-for="Family"
class="control-label">
</label>
<select asp-for="FamilyId"
class="form-control"
asp-items="ViewBag.FamilyId">
</select>
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="Name" <label asp-for="Name"
class="control-label"> class="control-label">
@@ -55,6 +74,16 @@
class="text-danger"> class="text-danger">
</span> </span>
</div> </div>
<div class="form-group">
<label asp-for="Model"
class="control-label">
</label>
<input asp-for="Model"
class="form-control" />
<span asp-validation-for="Model"
class="text-danger">
</span>
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="Introduced" <label asp-for="Introduced"
class="control-label"> class="control-label">
@@ -66,21 +95,14 @@
</span> </span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="FamilyId" <label asp-for="Type"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="FamilyId" <select asp-for="Type"
class="form-control" class="form-control"
asp-items="ViewBag.FamilyId"> asp-items="Html.GetEnumSelectList<MachineType>().OrderBy(s => s.Text)">
</select> </select>
</div> <span asp-validation-for="Type"
<div class="form-group">
<label asp-for="Model"
class="control-label">
</label>
<input asp-for="Model"
class="form-control" />
<span asp-validation-for="Model"
class="text-danger"> class="text-danger">
</span> </span>
</div> </div>

View File

@@ -42,30 +42,6 @@
<h4>Machine</h4> <h4>Machine</h4>
<hr /> <hr />
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Introduced)
</dt>
<dd>
@Html.DisplayFor(model => model.Introduced)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Model)
</dt>
<dd>
@Html.DisplayFor(model => model.Model)
</dd>
<dt> <dt>
@Html.DisplayNameFor(model => model.Company) @Html.DisplayNameFor(model => model.Company)
</dt> </dt>
@@ -78,6 +54,30 @@
<dd> <dd>
@Html.DisplayFor(model => model.Family.Name) @Html.DisplayFor(model => model.Family.Name)
</dd> </dd>
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Model)
</dt>
<dd>
@Html.DisplayFor(model => model.Model)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Introduced)
</dt>
<dd>
@Html.DisplayFor(model => model.Introduced)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
</dl> </dl>
<form asp-action="Delete"> <form asp-action="Delete">

View File

@@ -41,30 +41,6 @@
<h4>Machine</h4> <h4>Machine</h4>
<hr /> <hr />
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Introduced)
</dt>
<dd>
@Html.DisplayFor(model => model.Introduced)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Model)
</dt>
<dd>
@Html.DisplayFor(model => model.Model)
</dd>
<dt> <dt>
@Html.DisplayNameFor(model => model.Company) @Html.DisplayNameFor(model => model.Company)
</dt> </dt>
@@ -77,9 +53,40 @@
<dd> <dd>
@Html.DisplayFor(model => model.Family.Name) @Html.DisplayFor(model => model.Family.Name)
</dd> </dd>
<dt>
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd>
@Html.DisplayFor(model => model.Name)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Model)
</dt>
<dd>
@Html.DisplayFor(model => model.Model)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Introduced)
</dt>
<dd>
@Html.DisplayFor(model => model.Introduced)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Type)
</dt>
<dd>
@Html.DisplayFor(model => model.Type)
</dd>
</dl> </dl>
</div> </div>
<div> <div>
<a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-primary">Edit</a> <a asp-action="Edit"
<a asp-action="Index" class="btn btn-secondary">Back to List</a> asp-route-id="@Model.Id"
class="btn btn-primary">
Edit
</a>
<a asp-action="Index"
class="btn btn-secondary">
Back to List
</a>
</div> </div>

View File

@@ -29,6 +29,7 @@
// Copyright © 2003-2018 Natalia Portillo // Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/ *******************************************************************************/
} }
@using Cicm.Database
@model Cicm.Database.Models.Machine @model Cicm.Database.Models.Machine
@{ @{
@@ -48,16 +49,22 @@
<input type="hidden" <input type="hidden"
asp-for="Id" /> asp-for="Id" />
<div class="form-group"> <div class="form-group">
<label asp-for="CompanyId" <label asp-for="Company"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="CompanyId" <select asp-for="CompanyId"
class="form-control" class="form-control"
asp-items="ViewBag.CompanyId"> asp-items="ViewBag.CompanyId">
</select> </select>
<span asp-validation-for="CompanyId" </div>
class="text-danger"> <div class="form-group">
</span> <label asp-for="Family"
class="control-label">
</label>
<select asp-for="FamilyId"
class="form-control"
asp-items="ViewBag.FamilyId">
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Name" <label asp-for="Name"
@@ -70,13 +77,12 @@
</span> </span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="Type" <label asp-for="Model"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="Type" <input asp-for="Model"
class="form-control"> class="form-control" />
</select> <span asp-validation-for="Model"
<span asp-validation-for="Type"
class="text-danger"> class="text-danger">
</span> </span>
</div> </div>
@@ -91,24 +97,14 @@
</span> </span>
</div> </div>
<div class="form-group"> <div class="form-group">
<label asp-for="FamilyId" <label asp-for="Type"
class="control-label"> class="control-label">
</label> </label>
<select asp-for="FamilyId" <select asp-for="Type"
class="form-control" class="form-control"
asp-items="ViewBag.FamilyId"> asp-items="Html.GetEnumSelectList<MachineType>().OrderBy(s => s.Text)">
</select> </select>
<span asp-validation-for="FamilyId" <span asp-validation-for="Type"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Model"
class="control-label">
</label>
<input asp-for="Model"
class="form-control" />
<span asp-validation-for="Model"
class="text-danger"> class="text-danger">
</span> </span>
</div> </div>

View File

@@ -47,23 +47,23 @@
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
<th>
@Html.DisplayNameFor(model => model.Company)
</th>
<th>
@Html.DisplayNameFor(model => model.Family)
</th>
<th> <th>
@Html.DisplayNameFor(model => model.Name) @Html.DisplayNameFor(model => model.Name)
</th> </th>
<th>
@Html.DisplayNameFor(model => model.Type)
</th>
<th>
@Html.DisplayNameFor(model => model.Introduced)
</th>
<th> <th>
@Html.DisplayNameFor(model => model.Model) @Html.DisplayNameFor(model => model.Model)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Company) @Html.DisplayNameFor(model => model.Introduced)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Family) @Html.DisplayNameFor(model => model.Type)
</th> </th>
<th></th> <th></th>
</tr> </tr>
@@ -72,23 +72,23 @@
@foreach(Machine item in Model) @foreach(Machine item in Model)
{ {
<tr> <tr>
<td>
@Html.DisplayFor(modelItem => item.Company.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Family.Name)
</td>
<td> <td>
@Html.DisplayFor(modelItem => item.Name) @Html.DisplayFor(modelItem => item.Name)
</td> </td>
<td>
@Html.DisplayFor(modelItem => item.Type)
</td>
<td>
@Html.DisplayFor(modelItem => item.Introduced)
</td>
<td> <td>
@Html.DisplayFor(modelItem => item.Model) @Html.DisplayFor(modelItem => item.Model)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Company.Name) @Html.DisplayFor(modelItem => item.IntroducedView)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Family.Name) @Html.DisplayFor(modelItem => item.Type)
</td> </td>
<td> <td>
<a asp-action="Details" <a asp-action="Details"

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.435</Version> <Version>3.0.99.436</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>