diff --git a/Cicm.Database/Models/GpusByMachine.cs b/Cicm.Database/Models/GpusByMachine.cs index b3533737..fb1b3fb5 100644 --- a/Cicm.Database/Models/GpusByMachine.cs +++ b/Cicm.Database/Models/GpusByMachine.cs @@ -28,6 +28,8 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ +using System.ComponentModel; + namespace Cicm.Database.Models { public class GpusByMachine @@ -36,7 +38,8 @@ namespace Cicm.Database.Models public int MachineId { get; set; } public long Id { get; set; } - public virtual Gpu Gpu { get; set; } + [DisplayName("GPU")] + public virtual Gpu Gpu { get; set; } public virtual Machine Machine { get; set; } } } \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Controllers/GpusByMachineController.cs b/cicm_web/Areas/Admin/Controllers/GpusByMachineController.cs new file mode 100644 index 00000000..a2e19917 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/GpusByMachineController.cs @@ -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 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 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 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 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 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 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 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); + } + } +} diff --git a/cicm_web/Areas/Admin/Views/GpusByMachine/Create.cshtml b/cicm_web/Areas/Admin/Views/GpusByMachine/Create.cshtml new file mode 100644 index 00000000..cd2d641d --- /dev/null +++ b/cicm_web/Areas/Admin/Views/GpusByMachine/Create.cshtml @@ -0,0 +1,30 @@ +@model Cicm.Database.Models.GpusByMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

GPU by machine

+
+
+
+
+
+
+ + +
+
+ + +
+
+ + Back to List +
+
+
+
+ diff --git a/cicm_web/Areas/Admin/Views/GpusByMachine/Delete.cshtml b/cicm_web/Areas/Admin/Views/GpusByMachine/Delete.cshtml new file mode 100644 index 00000000..92bc6867 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/GpusByMachine/Delete.cshtml @@ -0,0 +1,33 @@ +@model Cicm.Database.Models.GpusByMachine + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

GPU by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Gpu) +
+
+ @Html.DisplayFor(model => model.Gpu.Name) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine.Name) +
+
+ +
+ + + Back to List +
+
diff --git a/cicm_web/Areas/Admin/Views/GpusByMachine/Details.cshtml b/cicm_web/Areas/Admin/Views/GpusByMachine/Details.cshtml new file mode 100644 index 00000000..dc247dad --- /dev/null +++ b/cicm_web/Areas/Admin/Views/GpusByMachine/Details.cshtml @@ -0,0 +1,30 @@ +@model Cicm.Database.Models.GpusByMachine + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

GPU by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Gpu) +
+
+ @Html.DisplayFor(model => model.Gpu.Name) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine.Name) +
+
+
+ diff --git a/cicm_web/Areas/Admin/Views/GpusByMachine/Edit.cshtml b/cicm_web/Areas/Admin/Views/GpusByMachine/Edit.cshtml new file mode 100644 index 00000000..158d1b98 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/GpusByMachine/Edit.cshtml @@ -0,0 +1,33 @@ +@model Cicm.Database.Models.GpusByMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

GpusByMachine

+
+
+
+
+
+
+ + + +
+
+ + + +
+ +
+ + Back to List +
+
+
+
+ diff --git a/cicm_web/Areas/Admin/Views/GpusByMachine/Index.cshtml b/cicm_web/Areas/Admin/Views/GpusByMachine/Index.cshtml new file mode 100644 index 00000000..bf75a626 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/GpusByMachine/Index.cshtml @@ -0,0 +1,41 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

GPUs by machine

+ +

+ Create New +

+ + + + + + + + + +@foreach (var item in Model) { + + + + + +} + +
+ @Html.DisplayNameFor(model => model.Gpu) + + @Html.DisplayNameFor(model => model.Machine) +
+ @Html.DisplayFor(modelItem => item.Gpu.Name) + + @Html.DisplayFor(modelItem => item.Machine.Name) + + Details + Edit + Delete +
diff --git a/cicm_web/Areas/Admin/Views/Home/Index.cshtml b/cicm_web/Areas/Admin/Views/Home/Index.cshtml index 6c51b561..16311d15 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -40,6 +40,7 @@ Companies
Company descriptions
GPUs
+ GPUs by machine
Instruction sets
Instruction set extensions
Machine families
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 4010ff0c..e9e4b63f 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.451 + 3.0.99.456 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website