2019-05-19 02:24:01 +01:00
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
2020-02-10 02:10:18 +00:00
|
|
|
using Marechai.Database.Models;
|
2019-05-20 01:11:45 +01:00
|
|
|
using cicm_web.Areas.Admin.Models;
|
2019-05-19 02:24:01 +01:00
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2019-05-19 22:08:15 +01:00
|
|
|
using Microsoft.EntityFrameworkCore.Query;
|
2019-05-19 02:24:01 +01:00
|
|
|
|
|
|
|
|
namespace cicm_web.Areas.Admin.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Area("Admin")]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class GpusByMachineController : Controller
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
readonly cicmContext _context;
|
2019-05-19 02:24:01 +01:00
|
|
|
|
|
|
|
|
public GpusByMachineController(cicmContext context)
|
|
|
|
|
{
|
|
|
|
|
_context = context;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: GpusByMachine
|
|
|
|
|
public async Task<IActionResult> Index()
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
IIncludableQueryable<GpusByMachine, Machine> cicmContext =
|
|
|
|
|
_context.GpusByMachine.Include(g => g.Gpu).Include(g => g.Machine);
|
2019-05-20 01:11:45 +01:00
|
|
|
return View(await cicmContext.OrderBy(g => g.Machine.Name).ThenBy(g => g.Gpu.Name)
|
|
|
|
|
.Select(g => new GpusByMachineViewModel
|
|
|
|
|
{
|
|
|
|
|
Id = g.Id, Gpu = g.Gpu.Name, Machine = g.Machine.Name
|
|
|
|
|
}).ToListAsync());
|
2019-05-19 02:24:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: GpusByMachine/Details/5
|
|
|
|
|
public async Task<IActionResult> Details(long? id)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
2019-05-19 22:08:15 +01:00
|
|
|
GpusByMachine gpusByMachine = await _context.GpusByMachine
|
|
|
|
|
.Include(g => g.Gpu).Include(g => g.Machine)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(gpusByMachine == null) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
|
|
|
|
return View(gpusByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: GpusByMachine/Create
|
|
|
|
|
public IActionResult Create()
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
ViewData["GpuId"] = new SelectList(_context.Gpus.OrderBy(g => g.Name), "Id", "Name");
|
|
|
|
|
ViewData["MachineId"] = new SelectList(_context.Machines.OrderBy(m => m.Name), "Id", "Name");
|
2019-05-19 02:24:01 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(ModelState.IsValid)
|
2019-05-19 02:24:01 +01:00
|
|
|
{
|
|
|
|
|
_context.Add(gpusByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
2019-05-19 22:08:15 +01:00
|
|
|
|
|
|
|
|
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);
|
2019-05-19 02:24:01 +01:00
|
|
|
return View(gpusByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: GpusByMachine/Edit/5
|
|
|
|
|
public async Task<IActionResult> Edit(long? id)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
2019-05-19 22:08:15 +01:00
|
|
|
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);
|
2019-05-19 02:24:01 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(id != gpusByMachine.Id) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
2019-05-19 22:08:15 +01:00
|
|
|
if(ModelState.IsValid)
|
2019-05-19 02:24:01 +01:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_context.Update(gpusByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
}
|
2019-05-19 22:08:15 +01:00
|
|
|
catch(DbUpdateConcurrencyException)
|
2019-05-19 02:24:01 +01:00
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(!GpusByMachineExists(gpusByMachine.Id)) return NotFound();
|
|
|
|
|
|
|
|
|
|
throw;
|
2019-05-19 02:24:01 +01:00
|
|
|
}
|
2019-05-19 22:08:15 +01:00
|
|
|
|
2019-05-19 02:24:01 +01:00
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
2019-05-19 22:08:15 +01:00
|
|
|
|
|
|
|
|
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);
|
2019-05-19 02:24:01 +01:00
|
|
|
return View(gpusByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET: GpusByMachine/Delete/5
|
|
|
|
|
public async Task<IActionResult> Delete(long? id)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
if(id == null) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
2019-05-19 22:08:15 +01:00
|
|
|
GpusByMachine gpusByMachine = await _context.GpusByMachine
|
|
|
|
|
.Include(g => g.Gpu).Include(g => g.Machine)
|
|
|
|
|
.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
|
if(gpusByMachine == null) return NotFound();
|
2019-05-19 02:24:01 +01:00
|
|
|
|
|
|
|
|
return View(gpusByMachine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST: GpusByMachine/Delete/5
|
2019-05-19 22:08:15 +01:00
|
|
|
[HttpPost]
|
|
|
|
|
[ActionName("Delete")]
|
2019-05-19 02:24:01 +01:00
|
|
|
[ValidateAntiForgeryToken]
|
|
|
|
|
public async Task<IActionResult> DeleteConfirmed(long id)
|
|
|
|
|
{
|
2019-05-19 22:08:15 +01:00
|
|
|
GpusByMachine gpusByMachine = await _context.GpusByMachine.FindAsync(id);
|
2019-05-19 02:24:01 +01:00
|
|
|
_context.GpusByMachine.Remove(gpusByMachine);
|
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-19 22:08:15 +01:00
|
|
|
bool GpusByMachineExists(long id)
|
2019-05-19 02:24:01 +01:00
|
|
|
{
|
|
|
|
|
return _context.GpusByMachine.Any(e => e.Id == id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-19 22:08:15 +01:00
|
|
|
}
|