mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Implement GPUs by owned machine admin pages.
This commit is contained in:
183
cicm_web/Areas/Admin/Controllers/GpusByOwnedMachineController.cs
Normal file
183
cicm_web/Areas/Admin/Controllers/GpusByOwnedMachineController.cs
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Cicm.Database.Models;
|
||||||
|
using cicm_web.Areas.Admin.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
|
||||||
|
{
|
||||||
|
[Area("Admin")]
|
||||||
|
[Authorize]
|
||||||
|
public class GpusByOwnedMachineController : Controller
|
||||||
|
{
|
||||||
|
readonly cicmContext _context;
|
||||||
|
|
||||||
|
public GpusByOwnedMachineController(cicmContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: GpusByOwnedMachine
|
||||||
|
public async Task<IActionResult> Index()
|
||||||
|
{
|
||||||
|
IIncludableQueryable<GpusByOwnedMachine, OwnedMachine> cicmContext =
|
||||||
|
_context.GpusByOwnedMachine.Include(g => g.Gpu).Include(g => g.OwnedMachine);
|
||||||
|
return View(await cicmContext.OrderBy(g => g.OwnedMachine.Machine.Name).ThenBy(g => g.Gpu.Name)
|
||||||
|
.Select(g => new GpusByMachineViewModel
|
||||||
|
{
|
||||||
|
Id = g.Id,
|
||||||
|
Gpu = g.Gpu.Name,
|
||||||
|
Machine =
|
||||||
|
$"{g.OwnedMachine.Machine.Company.Name} {g.OwnedMachine.Machine.Name} <{g.OwnedMachine.User.UserName}>"
|
||||||
|
}).ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: GpusByOwnedMachine/Details/5
|
||||||
|
public async Task<IActionResult> Details(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
GpusByMachineViewModel gpusByOwnedMachine = await _context.GpusByOwnedMachine
|
||||||
|
.Include(g => g.Gpu).Include(g => g.OwnedMachine)
|
||||||
|
.Select(o => new GpusByMachineViewModel
|
||||||
|
{
|
||||||
|
Gpu = o.Gpu.Name,
|
||||||
|
Id = o.Id,
|
||||||
|
Machine =
|
||||||
|
$"{o.OwnedMachine.Machine.Company.Name} {o.OwnedMachine.Machine.Name} <{o.OwnedMachine.User.UserName}>"
|
||||||
|
}).FirstOrDefaultAsync(m => m.Id ==
|
||||||
|
id);
|
||||||
|
if(gpusByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
return View(gpusByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: GpusByOwnedMachine/Create
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name");
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: GpusByOwnedMachine/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,OwnedMachineId,Id")] GpusByOwnedMachine gpusByOwnedMachine)
|
||||||
|
{
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
_context.Add(gpusByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewData["GpuId"] =
|
||||||
|
new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByOwnedMachine.GpuId);
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", gpusByOwnedMachine.OwnedMachineId);
|
||||||
|
return View(gpusByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: GpusByOwnedMachine/Edit/5
|
||||||
|
public async Task<IActionResult> Edit(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
GpusByOwnedMachine gpusByOwnedMachine = await _context.GpusByOwnedMachine.FindAsync(id);
|
||||||
|
if(gpusByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
ViewData["GpuId"] =
|
||||||
|
new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByOwnedMachine.GpuId);
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", gpusByOwnedMachine.OwnedMachineId);
|
||||||
|
return View(gpusByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: GpusByOwnedMachine/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,OwnedMachineId,Id")] GpusByOwnedMachine gpusByOwnedMachine)
|
||||||
|
{
|
||||||
|
if(id != gpusByOwnedMachine.Id) return NotFound();
|
||||||
|
|
||||||
|
if(ModelState.IsValid)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Update(gpusByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
catch(DbUpdateConcurrencyException)
|
||||||
|
{
|
||||||
|
if(!GpusByOwnedMachineExists(gpusByOwnedMachine.Id)) return NotFound();
|
||||||
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
ViewData["GpuId"] =
|
||||||
|
new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name", gpusByOwnedMachine.GpuId);
|
||||||
|
ViewData["OwnedMachineId"] =
|
||||||
|
new
|
||||||
|
SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}),
|
||||||
|
"Id", "Name", gpusByOwnedMachine.OwnedMachineId);
|
||||||
|
return View(gpusByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: GpusByOwnedMachine/Delete/5
|
||||||
|
public async Task<IActionResult> Delete(long? id)
|
||||||
|
{
|
||||||
|
if(id == null) return NotFound();
|
||||||
|
|
||||||
|
GpusByMachineViewModel gpusByOwnedMachine = await _context.GpusByOwnedMachine
|
||||||
|
.Include(g => g.Gpu).Include(g => g.OwnedMachine)
|
||||||
|
.Select(o => new GpusByMachineViewModel
|
||||||
|
{
|
||||||
|
Gpu = o.Gpu.Name,
|
||||||
|
Id = o.Id,
|
||||||
|
Machine =
|
||||||
|
$"{o.OwnedMachine.Machine.Company.Name} {o.OwnedMachine.Machine.Name} <{o.OwnedMachine.User.UserName}>"
|
||||||
|
}).FirstOrDefaultAsync(m => m.Id ==
|
||||||
|
id);
|
||||||
|
if(gpusByOwnedMachine == null) return NotFound();
|
||||||
|
|
||||||
|
return View(gpusByOwnedMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: GpusByOwnedMachine/Delete/5
|
||||||
|
[HttpPost]
|
||||||
|
[ActionName("Delete")]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
||||||
|
{
|
||||||
|
GpusByOwnedMachine gpusByOwnedMachine = await _context.GpusByOwnedMachine.FindAsync(id);
|
||||||
|
_context.GpusByOwnedMachine.Remove(gpusByOwnedMachine);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GpusByOwnedMachineExists(long id)
|
||||||
|
{
|
||||||
|
return _context.GpusByOwnedMachine.Any(e => e.Id == id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
46
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Create.cshtml
Normal file
46
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Create.cshtml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
@model Cicm.Database.Models.GpusByOwnedMachine
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Create</h1>
|
||||||
|
|
||||||
|
<h4>GPU by owned 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="OwnedMachine"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="OwnedMachineId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.OwnedMachineId">
|
||||||
|
</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 class="btn btn-primary"
|
||||||
|
type="submit"
|
||||||
|
value="Create" />
|
||||||
|
<a asp-action="Index"
|
||||||
|
class="btn btn-secondary">
|
||||||
|
Back to List
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
39
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Delete.cshtml
Normal file
39
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Delete.cshtml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
@model cicm_web.Areas.Admin.Models.GpusByMachineViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Delete";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Delete</h1>
|
||||||
|
|
||||||
|
<h3>Are you sure you want to delete this?</h3>
|
||||||
|
<div>
|
||||||
|
<h4>GPU by owned machine</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Machine)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Machine)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Gpu)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Gpu)
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<form asp-action="Delete">
|
||||||
|
<input type="hidden"
|
||||||
|
asp-for="Id" />
|
||||||
|
<input class="btn btn-danger"
|
||||||
|
type="submit"
|
||||||
|
value="Delete" />
|
||||||
|
<a asp-action="Index"
|
||||||
|
class="btn btn-secondary">
|
||||||
|
Back to List
|
||||||
|
</a>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
37
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Details.cshtml
Normal file
37
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Details.cshtml
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
@model cicm_web.Areas.Admin.Models.GpusByMachineViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Details";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Details</h1>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<h4>GPU by owned machine</h4>
|
||||||
|
<hr />
|
||||||
|
<dl class="row">
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Machine)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Machine)
|
||||||
|
</dd>
|
||||||
|
<dt class="col-sm-2">
|
||||||
|
@Html.DisplayNameFor(model => model.Gpu)
|
||||||
|
</dt>
|
||||||
|
<dd class="col-sm-10">
|
||||||
|
@Html.DisplayFor(model => model.Gpu)
|
||||||
|
</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>
|
||||||
54
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Edit.cshtml
Normal file
54
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Edit.cshtml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
@model Cicm.Database.Models.GpusByOwnedMachine
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1>Edit</h1>
|
||||||
|
|
||||||
|
<h4>Gpus by owned machine</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="OwnedMachine"
|
||||||
|
class="control-label">
|
||||||
|
</label>
|
||||||
|
<select asp-for="OwnedMachineId"
|
||||||
|
class="form-control"
|
||||||
|
asp-items="ViewBag.OwnedMachineId">
|
||||||
|
</select>
|
||||||
|
<span asp-validation-for="OwnedMachineId"
|
||||||
|
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 class="btn btn-primary"
|
||||||
|
type="submit"
|
||||||
|
value="Save" />
|
||||||
|
<a asp-action="Index"
|
||||||
|
class="btn btn-secondary">
|
||||||
|
Back to List
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
58
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Index.cshtml
Normal file
58
cicm_web/Areas/Admin/Views/GpusByOwnedMachine/Index.cshtml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
@using cicm_web.Areas.Admin.Models
|
||||||
|
@model IEnumerable<cicm_web.Areas.Admin.Models.GpusByMachineViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
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.Machine)
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
@Html.DisplayNameFor(model => model.Gpu)
|
||||||
|
</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach(GpusByMachineViewModel item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Machine)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Gpu)
|
||||||
|
</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>
|
||||||
Reference in New Issue
Block a user