Add admin page for resolution by GPU.

This commit is contained in:
2019-05-19 15:26:59 +01:00
parent 8762cf2cbd
commit c0df1ed4b6
9 changed files with 414 additions and 2 deletions

View File

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

View File

@@ -0,0 +1,173 @@
using System.Linq;
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
{
[Area("Admin")]
[Authorize]
public class ResolutionsByGpuController : Controller
{
readonly cicmContext _context;
public ResolutionsByGpuController(cicmContext context)
{
_context = context;
}
// GET: ResolutionsByGpu
public async Task<IActionResult> Index()
{
IIncludableQueryable<ResolutionsByGpu, Resolution> cicmContext =
_context.ResolutionsByGpu.Include(r => r.Gpu).Include(r => r.Resolution);
return View(await cicmContext.OrderBy(r => r.Gpu.Company.Name).ThenBy(r => r.Gpu.Name)
.ThenBy(r => r.Resolution.Chars).ThenBy(r => r.Resolution.Width)
.ThenBy(r => r.Resolution.Height).ThenBy(r => r.Resolution.Colors)
.ToListAsync());
}
// GET: ResolutionsByGpu/Details/5
public async Task<IActionResult> Details(long? id)
{
if(id == null) return NotFound();
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu
.Include(r => r.Gpu).Include(r => r.Resolution)
.FirstOrDefaultAsync(m => m.Id == id);
if(resolutionsByGpu == null) return NotFound();
return View(resolutionsByGpu);
}
// GET: ResolutionsByGpu/Create
public IActionResult Create()
{
ViewData["GpuId"] =
new
SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).Select(g => new {g.Id, Name = $"{g.Company.Name} {g.Name}"}),
"Id", "Name");
ViewData["ResolutionId"] =
new
SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).ThenBy(r => r.Height).ThenBy(r => r.Colors).Select(r => new {r.Id, Name = r.ToString()}),
"Id", "Name");
return View();
}
// POST: ResolutionsByGpu/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,ResolutionId,Id")] ResolutionsByGpu resolutionsByGpu)
{
if(ModelState.IsValid)
{
_context.Add(resolutionsByGpu);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["GpuId"] =
new
SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).Select(g => new {g.Id, Name = $"{g.Company.Name} {g.Name}"}),
"Id", "Name", resolutionsByGpu.GpuId);
ViewData["ResolutionId"] =
new
SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).ThenBy(r => r.Height).ThenBy(r => r.Colors).Select(r => new {r.Id, Name = r.ToString()}),
"Id", "Name", resolutionsByGpu.ResolutionId);
return View(resolutionsByGpu);
}
// GET: ResolutionsByGpu/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if(id == null) return NotFound();
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu.FindAsync(id);
if(resolutionsByGpu == null) return NotFound();
ViewData["GpuId"] =
new
SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).Select(g => new {g.Id, Name = $"{g.Company.Name} {g.Name}"}),
"Id", "Name", resolutionsByGpu.GpuId);
ViewData["ResolutionId"] =
new
SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).ThenBy(r => r.Height).ThenBy(r => r.Colors).Select(r => new {r.Id, Name = r.ToString()}),
"Id", "Name", resolutionsByGpu.ResolutionId);
return View(resolutionsByGpu);
}
// POST: ResolutionsByGpu/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,ResolutionId,Id")] ResolutionsByGpu resolutionsByGpu)
{
if(id != resolutionsByGpu.Id) return NotFound();
if(ModelState.IsValid)
{
try
{
_context.Update(resolutionsByGpu);
await _context.SaveChangesAsync();
}
catch(DbUpdateConcurrencyException)
{
if(!ResolutionsByGpuExists(resolutionsByGpu.Id)) return NotFound();
throw;
}
return RedirectToAction(nameof(Index));
}
ViewData["GpuId"] =
new
SelectList(_context.Gpus.OrderBy(r => r.Company.Name).ThenBy(r => r.Name).Select(g => new {g.Id, Name = $"{g.Company.Name} {g.Name}"}),
"Id", "Name", resolutionsByGpu.GpuId);
ViewData["ResolutionId"] =
new
SelectList(_context.Resolutions.OrderBy(r => r.Chars).ThenBy(r => r.Width).ThenBy(r => r.Height).ThenBy(r => r.Colors).Select(r => new {r.Id, Name = r.ToString()}),
"Id", "Name", resolutionsByGpu.ResolutionId);
return View(resolutionsByGpu);
}
// GET: ResolutionsByGpu/Delete/5
public async Task<IActionResult> Delete(long? id)
{
if(id == null) return NotFound();
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu
.Include(r => r.Gpu).Include(r => r.Resolution)
.FirstOrDefaultAsync(m => m.Id == id);
if(resolutionsByGpu == null) return NotFound();
return View(resolutionsByGpu);
}
// POST: ResolutionsByGpu/Delete/5
[HttpPost]
[ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
ResolutionsByGpu resolutionsByGpu = await _context.ResolutionsByGpu.FindAsync(id);
_context.ResolutionsByGpu.Remove(resolutionsByGpu);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
bool ResolutionsByGpuExists(long id)
{
return _context.ResolutionsByGpu.Any(e => e.Id == id);
}
}
}

View File

@@ -52,6 +52,7 @@
<a asp-controller="ProcessorsByMachines">Processors by machines</a><br /> <a asp-controller="ProcessorsByMachines">Processors by machines</a><br />
<a asp-controller="Processors">Processors</a><br /> <a asp-controller="Processors">Processors</a><br />
<a asp-controller="Resolutions">Resolutions</a><br /> <a asp-controller="Resolutions">Resolutions</a><br />
<a asp-controller="ResolutionsByGpu">Resolutions by GPU</a><br />
<a asp-controller="SoundSynths">Sound synthetizers</a><br /> <a asp-controller="SoundSynths">Sound synthetizers</a><br />
<a asp-controller="StorageByMachines">Storage by machines</a><br /> <a asp-controller="StorageByMachines">Storage by machines</a><br />
</div> </div>

View File

@@ -0,0 +1,46 @@
@model Cicm.Database.Models.ResolutionsByGpu
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>Resolutions by GPU</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="Resolution"
class="control-label">
</label>
<select asp-for="ResolutionId"
class="form-control"
asp-items="ViewBag.ResolutionId">
</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>

View File

@@ -0,0 +1,39 @@
@model Cicm.Database.Models.ResolutionsByGpu
@{
ViewData["Title"] = "Delete";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Resolution by GPU</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.Resolution)
</dt>
<dd class="col-sm-10">
@Model.Resolution.ToString()
</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>

View File

@@ -0,0 +1,37 @@
@model Cicm.Database.Models.ResolutionsByGpu
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>Resolution by GPU</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.Resolution)
</dt>
<dd class="col-sm-10">
@Model.Resolution.ToString()
</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,54 @@
@model Cicm.Database.Models.ResolutionsByGpu
@{
ViewData["Title"] = "Edit";
}
<h1>Edit</h1>
<h4>Resolution by GPU</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="GpuId"
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="ResolutionId"
class="control-label">
</label>
<select asp-for="ResolutionId"
class="form-control"
asp-items="ViewBag.ResolutionId">
</select>
<span asp-validation-for="ResolutionId"
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>

View File

@@ -0,0 +1,59 @@
@using Cicm.Database.Models
@model IEnumerable<Cicm.Database.Models.ResolutionsByGpu>
@{
ViewData["Title"] = "Index";
}
<h1>Resolutions by GPU</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.Resolution)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(ResolutionsByGpu item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Gpu.Company.Name)
@Html.DisplayFor(modelItem => item.Gpu.Name)
</td>
<td>
@item.Resolution
</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

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