Sort in GPUs by machine admin pages.

This commit is contained in:
2019-05-19 22:08:15 +01:00
parent 1c1d44cd08
commit 2785155680
7 changed files with 70 additions and 89 deletions

View File

@@ -1,11 +1,11 @@
using System.Linq; using System.Linq;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Cicm.Database.Models; using Cicm.Database.Models;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
namespace cicm_web.Areas.Admin.Controllers namespace cicm_web.Areas.Admin.Controllers
{ {
@@ -13,7 +13,7 @@ namespace cicm_web.Areas.Admin.Controllers
[Authorize] [Authorize]
public class GpusByMachineController : Controller public class GpusByMachineController : Controller
{ {
private readonly cicmContext _context; readonly cicmContext _context;
public GpusByMachineController(cicmContext context) public GpusByMachineController(cicmContext context)
{ {
@@ -23,26 +23,20 @@ namespace cicm_web.Areas.Admin.Controllers
// GET: GpusByMachine // GET: GpusByMachine
public async Task<IActionResult> Index() public async Task<IActionResult> Index()
{ {
var cicmContext = _context.GpusByMachine.Include(g => g.Gpu).Include(g => g.Machine); IIncludableQueryable<GpusByMachine, Machine> cicmContext =
_context.GpusByMachine.Include(g => g.Gpu).Include(g => g.Machine);
return View(await cicmContext.OrderBy(g => g.Machine.Name).ThenBy(g => g.Gpu.Name).ToListAsync()); return View(await cicmContext.OrderBy(g => g.Machine.Name).ThenBy(g => g.Gpu.Name).ToListAsync());
} }
// GET: GpusByMachine/Details/5 // GET: GpusByMachine/Details/5
public async Task<IActionResult> Details(long? id) public async Task<IActionResult> Details(long? id)
{ {
if (id == null) if(id == null) return NotFound();
{
return NotFound();
}
var gpusByMachine = await _context.GpusByMachine GpusByMachine gpusByMachine = await _context.GpusByMachine
.Include(g => g.Gpu) .Include(g => g.Gpu).Include(g => g.Machine)
.Include(g => g.Machine) .FirstOrDefaultAsync(m => m.Id == id);
.FirstOrDefaultAsync(m => m.Id == id); if(gpusByMachine == null) return NotFound();
if (gpusByMachine == null)
{
return NotFound();
}
return View(gpusByMachine); return View(gpusByMachine);
} }
@@ -50,8 +44,8 @@ namespace cicm_web.Areas.Admin.Controllers
// GET: GpusByMachine/Create // GET: GpusByMachine/Create
public IActionResult Create() public IActionResult Create()
{ {
ViewData["GpuId"] = new SelectList(_context.Gpus, "Id", "Name"); ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name");
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name"); ViewData["MachineId"] = new SelectList(_context.Machines.OrderBy(m => m.Name), "Id", "Name");
return View(); return View();
} }
@@ -62,32 +56,30 @@ namespace cicm_web.Areas.Admin.Controllers
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine) public async Task<IActionResult> Create([Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine)
{ {
if (ModelState.IsValid) if(ModelState.IsValid)
{ {
_context.Add(gpusByMachine); _context.Add(gpusByMachine);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
} }
ViewData["GpuId"] = new SelectList(_context.Gpus, "Id", "Name", gpusByMachine.GpuId);
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", gpusByMachine.MachineId); ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByMachine.GpuId);
ViewData["MachineId"] =
new SelectList(_context.Machines.OrderBy(m => m.Name), "Id", "Name", gpusByMachine.MachineId);
return View(gpusByMachine); return View(gpusByMachine);
} }
// GET: GpusByMachine/Edit/5 // GET: GpusByMachine/Edit/5
public async Task<IActionResult> Edit(long? id) public async Task<IActionResult> Edit(long? id)
{ {
if (id == null) if(id == null) return NotFound();
{
return NotFound();
}
var gpusByMachine = await _context.GpusByMachine.FindAsync(id); GpusByMachine gpusByMachine = await _context.GpusByMachine.FindAsync(id);
if (gpusByMachine == null) if(gpusByMachine == null) return NotFound();
{
return NotFound(); ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByMachine.GpuId);
} ViewData["MachineId"] =
ViewData["GpuId"] = new SelectList(_context.Gpus, "Id", "Name", gpusByMachine.GpuId); new SelectList(_context.Machines.OrderBy(m => m.Name), "Id", "Name", gpusByMachine.MachineId);
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", gpusByMachine.MachineId);
return View(gpusByMachine); return View(gpusByMachine);
} }
@@ -98,70 +90,59 @@ namespace cicm_web.Areas.Admin.Controllers
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, [Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine) public async Task<IActionResult> Edit(long id, [Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine)
{ {
if (id != gpusByMachine.Id) if(id != gpusByMachine.Id) return NotFound();
{
return NotFound();
}
if (ModelState.IsValid) if(ModelState.IsValid)
{ {
try try
{ {
_context.Update(gpusByMachine); _context.Update(gpusByMachine);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
} }
catch (DbUpdateConcurrencyException) catch(DbUpdateConcurrencyException)
{ {
if (!GpusByMachineExists(gpusByMachine.Id)) if(!GpusByMachineExists(gpusByMachine.Id)) return NotFound();
{
return NotFound(); throw;
}
else
{
throw;
}
} }
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
} }
ViewData["GpuId"] = new SelectList(_context.Gpus, "Id", "Name", gpusByMachine.GpuId);
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", gpusByMachine.MachineId); ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByMachine.GpuId);
ViewData["MachineId"] =
new SelectList(_context.Machines.OrderBy(m => m.Name), "Id", "Name", gpusByMachine.MachineId);
return View(gpusByMachine); return View(gpusByMachine);
} }
// GET: GpusByMachine/Delete/5 // GET: GpusByMachine/Delete/5
public async Task<IActionResult> Delete(long? id) public async Task<IActionResult> Delete(long? id)
{ {
if (id == null) if(id == null) return NotFound();
{
return NotFound();
}
var gpusByMachine = await _context.GpusByMachine GpusByMachine gpusByMachine = await _context.GpusByMachine
.Include(g => g.Gpu) .Include(g => g.Gpu).Include(g => g.Machine)
.Include(g => g.Machine) .FirstOrDefaultAsync(m => m.Id == id);
.FirstOrDefaultAsync(m => m.Id == id); if(gpusByMachine == null) return NotFound();
if (gpusByMachine == null)
{
return NotFound();
}
return View(gpusByMachine); return View(gpusByMachine);
} }
// POST: GpusByMachine/Delete/5 // POST: GpusByMachine/Delete/5
[HttpPost, ActionName("Delete")] [HttpPost]
[ActionName("Delete")]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id) public async Task<IActionResult> DeleteConfirmed(long id)
{ {
var gpusByMachine = await _context.GpusByMachine.FindAsync(id); GpusByMachine gpusByMachine = await _context.GpusByMachine.FindAsync(id);
_context.GpusByMachine.Remove(gpusByMachine); _context.GpusByMachine.Remove(gpusByMachine);
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
} }
private bool GpusByMachineExists(long id) bool GpusByMachineExists(long id)
{ {
return _context.GpusByMachine.Any(e => e.Id == id); return _context.GpusByMachine.Any(e => e.Id == id);
} }
} }
} }

View File

@@ -12,14 +12,14 @@
<div class="col-md-4"> <div class="col-md-4">
<form asp-action="Create"> <form asp-action="Create">
<div asp-validation-summary="ModelOnly" class="text-danger"></div> <div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Gpu" class="control-label"></label>
<select asp-for="GpuId" class ="form-control" asp-items="ViewBag.GpuId"></select>
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="Machine" class="control-label"></label> <label asp-for="Machine" class="control-label"></label>
<select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select> <select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select>
</div> </div>
<div class="form-group">
<label asp-for="Gpu" class="control-label"></label>
<select asp-for="GpuId" class ="form-control" asp-items="ViewBag.GpuId"></select>
</div>
<div class="form-group"> <div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" /> <input type="submit" value="Create" class="btn btn-primary" />
<a asp-action="Index" class="btn btn-secondary">Back to List</a> <a asp-action="Index" class="btn btn-secondary">Back to List</a>

View File

@@ -11,18 +11,18 @@
<h4>GPU by machine</h4> <h4>GPU by machine</h4>
<hr /> <hr />
<dl class="row"> <dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Gpu)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Gpu.Name)
</dd>
<dt class = "col-sm-2"> <dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Machine) @Html.DisplayNameFor(model => model.Machine)
</dt> </dt>
<dd class = "col-sm-10"> <dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name) @Html.DisplayFor(model => model.Machine.Name)
</dd> </dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Gpu)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Gpu.Name)
</dd>
</dl> </dl>
<form asp-action="Delete"> <form asp-action="Delete">

View File

@@ -10,18 +10,18 @@
<h4>GPU by machine</h4> <h4>GPU by machine</h4>
<hr /> <hr />
<dl class="row"> <dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Gpu)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Gpu.Name)
</dd>
<dt class = "col-sm-2"> <dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Machine) @Html.DisplayNameFor(model => model.Machine)
</dt> </dt>
<dd class = "col-sm-10"> <dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name) @Html.DisplayFor(model => model.Machine.Name)
</dd> </dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Gpu)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Gpu.Name)
</dd>
</dl> </dl>
</div> </div>
<div> <div>

View File

@@ -12,16 +12,16 @@
<div class="col-md-4"> <div class="col-md-4">
<form asp-action="Edit"> <form asp-action="Edit">
<div asp-validation-summary="ModelOnly" class="text-danger"></div> <div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Gpu" class="control-label"></label>
<select asp-for="GpuId" class="form-control" asp-items="ViewBag.GpuId"></select>
<span asp-validation-for="GpuId" class="text-danger"></span>
</div>
<div class="form-group"> <div class="form-group">
<label asp-for="Machine" class="control-label"></label> <label asp-for="Machine" class="control-label"></label>
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId"></select> <select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId"></select>
<span asp-validation-for="MachineId" class="text-danger"></span> <span asp-validation-for="MachineId" class="text-danger"></span>
</div> </div>
<div class="form-group">
<label asp-for="Gpu" class="control-label"></label>
<select asp-for="GpuId" class="form-control" asp-items="ViewBag.GpuId"></select>
<span asp-validation-for="GpuId" class="text-danger"></span>
</div>
<input type="hidden" asp-for="Id" /> <input type="hidden" asp-for="Id" />
<div class="form-group"> <div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" /> <input type="submit" value="Save" class="btn btn-primary" />

View File

@@ -13,10 +13,10 @@
<thead> <thead>
<tr> <tr>
<th> <th>
@Html.DisplayNameFor(model => model.Gpu) @Html.DisplayNameFor(model => model.Machine)
</th> </th>
<th> <th>
@Html.DisplayNameFor(model => model.Machine) @Html.DisplayNameFor(model => model.Gpu)
</th> </th>
<th></th> <th></th>
</tr> </tr>
@@ -25,10 +25,10 @@
@foreach (var item in Model) { @foreach (var item in Model) {
<tr> <tr>
<td> <td>
@Html.DisplayFor(modelItem => item.Gpu.Name) @Html.DisplayFor(modelItem => item.Machine.Name)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => item.Machine.Name) @Html.DisplayFor(modelItem => item.Gpu.Name)
</td> </td>
<td> <td>
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">Details</a> <a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">Details</a>

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.517</Version> <Version>3.0.99.518</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>