Add admin page for GPUs by machine.

This commit is contained in:
2019-05-19 02:24:01 +01:00
parent 7f4e733524
commit d2156aaf90
9 changed files with 340 additions and 2 deletions

View File

@@ -28,6 +28,8 @@
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
using System.ComponentModel;
namespace Cicm.Database.Models
{
public class GpusByMachine
@@ -36,6 +38,7 @@ namespace Cicm.Database.Models
public int MachineId { get; set; }
public long Id { get; set; }
[DisplayName("GPU")]
public virtual Gpu Gpu { get; set; }
public virtual Machine Machine { get; set; }
}

View File

@@ -0,0 +1,167 @@
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;
namespace cicm_web.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize]
public class GpusByMachineController : Controller
{
private readonly cicmContext _context;
public GpusByMachineController(cicmContext context)
{
_context = context;
}
// GET: GpusByMachine
public async Task<IActionResult> Index()
{
var 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();
}
var 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);
}
// GET: GpusByMachine/Create
public IActionResult Create()
{
ViewData["GpuId"] = new SelectList(_context.Gpus, "Id", "Name");
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
return View();
}
// POST: GpusByMachine/Create
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine)
{
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);
return View(gpusByMachine);
}
// GET: GpusByMachine/Edit/5
public async Task<IActionResult> Edit(long? id)
{
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);
return View(gpusByMachine);
}
// POST: GpusByMachine/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(long id, [Bind("GpuId,MachineId,Id")] GpusByMachine gpusByMachine)
{
if (id != gpusByMachine.Id)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(gpusByMachine);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!GpusByMachineExists(gpusByMachine.Id))
{
return NotFound();
}
else
{
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);
return View(gpusByMachine);
}
// GET: GpusByMachine/Delete/5
public async Task<IActionResult> Delete(long? id)
{
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();
}
return View(gpusByMachine);
}
// POST: GpusByMachine/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
var gpusByMachine = await _context.GpusByMachine.FindAsync(id);
_context.GpusByMachine.Remove(gpusByMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
private bool GpusByMachineExists(long id)
{
return _context.GpusByMachine.Any(e => e.Id == id);
}
}
}

View File

@@ -0,0 +1,30 @@
@model Cicm.Database.Models.GpusByMachine
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>GPU by machine</h4>
<hr />
<div class="row">
<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">
<input type="submit" value="Create" class="btn btn-primary" />
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
</div>
</form>
</div>
</div>

View File

@@ -0,0 +1,33 @@
@model Cicm.Database.Models.GpusByMachine
@{
ViewData["Title"] = "Delete";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
<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>
</dl>
<form asp-action="Delete">
<input type="hidden" asp-for="Id" />
<input type="submit" value="Delete" class="btn btn-danger" />
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
</form>
</div>

View File

@@ -0,0 +1,30 @@
@model Cicm.Database.Models.GpusByMachine
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<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>
</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>

View File

@@ -0,0 +1,33 @@
@model Cicm.Database.Models.GpusByMachine
@{
ViewData["Title"] = "Edit";
}
<h1>Edit</h1>
<h4>GpusByMachine</h4>
<hr />
<div class="row">
<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>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
<a asp-action="Index" class="btn btn-secondary">Back to List</a>
</div>
</form>
</div>
</div>

View File

@@ -0,0 +1,41 @@
@model IEnumerable<Cicm.Database.Models.GpusByMachine>
@{
ViewData["Title"] = "Index";
}
<h1>GPUs by machine</h1>
<p>
<a asp-action="Create" class="btn btn-primary">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Gpu)
</th>
<th>
@Html.DisplayNameFor(model => model.Machine)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Gpu.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Machine.Name)
</td>
<td>
<a asp-action="Details" asp-route-id="@item.Id" class="btn btn-primary">Details</a>
<a asp-action="Edit" asp-route-id="@item.Id" class="btn btn-secondary">Edit</a>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-danger">Delete</a>
</td>
</tr>
}
</tbody>
</table>

View File

@@ -40,6 +40,7 @@
<a asp-controller="Companies">Companies</a><br />
<a asp-controller="CompanyDescriptions">Company descriptions</a><br />
<a asp-controller="Gpus">GPUs</a><br />
<a asp-controller="GpusByMachine">GPUs by machine</a><br />
<a asp-controller="InstructionSets">Instruction sets</a><br />
<a asp-controller="InstructionSetExtensions">Instruction set extensions</a><br />
<a asp-controller="MachineFamilies">Machine families</a><br />

View File

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