mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Sort in GPUs by machine admin pages.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user