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

View File

@@ -12,14 +12,14 @@
<div class="col-md-4">
<form asp-action="Create">
<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">
<label asp-for="Machine" class="control-label"></label>
<select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select>
</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">
<input type="submit" value="Create" class="btn btn-primary" />
<a asp-action="Index" class="btn btn-secondary">Back to List</a>

View File

@@ -11,18 +11,18 @@
<h4>GPU by machine</h4>
<hr />
<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">
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name)
</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>
<form asp-action="Delete">

View File

@@ -10,18 +10,18 @@
<h4>GPU by machine</h4>
<hr />
<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">
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name)
</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>
</div>
<div>

View File

@@ -12,16 +12,16 @@
<div class="col-md-4">
<form asp-action="Edit">
<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">
<label asp-for="Machine" class="control-label"></label>
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId"></select>
<span asp-validation-for="MachineId" class="text-danger"></span>
</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" />
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />

View File

@@ -13,10 +13,10 @@
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Gpu)
@Html.DisplayNameFor(model => model.Machine)
</th>
<th>
@Html.DisplayNameFor(model => model.Machine)
@Html.DisplayNameFor(model => model.Gpu)
</th>
<th></th>
</tr>
@@ -25,10 +25,10 @@
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Gpu.Name)
@Html.DisplayFor(modelItem => item.Machine.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Machine.Name)
@Html.DisplayFor(modelItem => item.Gpu.Name)
</td>
<td>
<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">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.517</Version>
<Version>3.0.99.518</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>