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.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
namespace Cicm.Database.Models
{
@@ -59,5 +61,10 @@ namespace Cicm.Database.Models
public virtual ICollection<ProcessorsByMachine> Processors { get; set; }
public virtual ICollection<SoundByMachine> Sound { 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 =
_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

View File

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

View File

@@ -42,30 +42,6 @@
<h4>Machine</h4>
<hr />
<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>
@Html.DisplayNameFor(model => model.Company)
</dt>
@@ -78,6 +54,30 @@
<dd>
@Html.DisplayFor(model => model.Family.Name)
</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>
<form asp-action="Delete">

View File

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

View File

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

View File

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

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.435</Version>
<Version>3.0.99.436</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>