diff --git a/Cicm.Database/Models/ResolutionsByGpu.cs b/Cicm.Database/Models/ResolutionsByGpu.cs index 005babc5..81df6dd7 100644 --- a/Cicm.Database/Models/ResolutionsByGpu.cs +++ b/Cicm.Database/Models/ResolutionsByGpu.cs @@ -28,6 +28,8 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ +using System.ComponentModel; + namespace Cicm.Database.Models { public class ResolutionsByGpu @@ -36,7 +38,8 @@ namespace Cicm.Database.Models public int ResolutionId { 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; } } } \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs b/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs new file mode 100644 index 00000000..8b2811a7 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/ResolutionsByGpuController.cs @@ -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 Index() + { + IIncludableQueryable 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 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 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 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 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 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 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); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Home/Index.cshtml b/cicm_web/Areas/Admin/Views/Home/Index.cshtml index 41576682..6889c2a8 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -52,6 +52,7 @@ Processors by machines
Processors
Resolutions
+ Resolutions by GPU
Sound synthetizers
Storage by machines
diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Create.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Create.cshtml new file mode 100644 index 00000000..cbbd772d --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Create.cshtml @@ -0,0 +1,46 @@ +@model Cicm.Database.Models.ResolutionsByGpu + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Resolutions by GPU

+
+
+
+
+
+
+
+ + +
+
+ + +
+ +
+
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Delete.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Delete.cshtml new file mode 100644 index 00000000..250dbca1 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Delete.cshtml @@ -0,0 +1,39 @@ +@model Cicm.Database.Models.ResolutionsByGpu + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Resolution by GPU

+
+
+
+ @Html.DisplayNameFor(model => model.Gpu) +
+
+ @Html.DisplayFor(model => model.Gpu.Name) +
+
+ @Html.DisplayNameFor(model => model.Resolution) +
+
+ @Model.Resolution.ToString() +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Details.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Details.cshtml new file mode 100644 index 00000000..9b44df95 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Details.cshtml @@ -0,0 +1,37 @@ +@model Cicm.Database.Models.ResolutionsByGpu + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Resolution by GPU

+
+
+
+ @Html.DisplayNameFor(model => model.Gpu) +
+
+ @Html.DisplayFor(model => model.Gpu.Name) +
+
+ @Html.DisplayNameFor(model => model.Resolution) +
+
+ @Model.Resolution.ToString() +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Edit.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Edit.cshtml new file mode 100644 index 00000000..e99e8c54 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Edit.cshtml @@ -0,0 +1,54 @@ +@model Cicm.Database.Models.ResolutionsByGpu + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Resolution by GPU

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+ + +
+
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml new file mode 100644 index 00000000..97323bdb --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ResolutionsByGpu/Index.cshtml @@ -0,0 +1,59 @@ +@using Cicm.Database.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Resolutions by GPU

+ +

+ + Create New + +

+ + + + + + + + + + @foreach(ResolutionsByGpu item in Model) + { + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Gpu) + + @Html.DisplayNameFor(model => model.Resolution) +
+ @Html.DisplayFor(modelItem => item.Gpu.Company.Name) + @Html.DisplayFor(modelItem => item.Gpu.Name) + + @item.Resolution + + + Details + + + Edit + + + Delete + +
\ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index ac8157b7..cb1ef362 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.466 + 3.0.99.477 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website