From 4caf531735d889dc9b6811ceb6fde5cf50fdded1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 31 May 2019 00:44:11 +0100 Subject: [PATCH] Implement processor by owned machine admin pages. --- .../ProcessorsByOwnedMachinesController.cs | 215 ++++++++++++++++++ .../ProcessorsByOwnedMachines/Create.cshtml | 91 ++++++++ .../ProcessorsByOwnedMachines/Delete.cshtml | 76 +++++++ .../ProcessorsByOwnedMachines/Details.cshtml | 74 ++++++ .../ProcessorsByOwnedMachines/Edit.cshtml | 99 ++++++++ .../ProcessorsByOwnedMachines/Index.cshtml | 95 ++++++++ 6 files changed, 650 insertions(+) create mode 100644 cicm_web/Areas/Admin/Controllers/ProcessorsByOwnedMachinesController.cs create mode 100644 cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Create.cshtml create mode 100644 cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Delete.cshtml create mode 100644 cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Details.cshtml create mode 100644 cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Edit.cshtml create mode 100644 cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Index.cshtml diff --git a/cicm_web/Areas/Admin/Controllers/ProcessorsByOwnedMachinesController.cs b/cicm_web/Areas/Admin/Controllers/ProcessorsByOwnedMachinesController.cs new file mode 100644 index 00000000..965b7e71 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/ProcessorsByOwnedMachinesController.cs @@ -0,0 +1,215 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : ProcessorsByOwnedMachinesController.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Processors by machine admin controller +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System.Linq; +using System.Threading.Tasks; +using Cicm.Database.Models; +using cicm_web.Areas.Admin.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 ProcessorsByOwnedMachinesController : Controller + { + readonly cicmContext _context; + + public ProcessorsByOwnedMachinesController(cicmContext context) + { + _context = context; + } + + // GET: Admin/ProcessorsByOwnedMachines + public async Task Index() + { + IIncludableQueryable cicmContext = + _context.ProcessorsByOwnedMachine.Include(p => p.OwnedMachine).Include(p => p.Processor); + return View(await cicmContext.OrderBy(p => p.OwnedMachine.Machine.Name).ThenBy(p => p.Processor.Name) + .Select(p => new ProcessorsByMachineViewModel + { + Id = p.Id, + Machine = + $"{p.OwnedMachine.Machine.Company.Name} {p.OwnedMachine.Machine.Name} <{p.OwnedMachine.User.UserName}>", + Processor = p.Processor.Name, + Speed = p.Speed + }).ToListAsync()); + } + + // GET: Admin/ProcessorsByOwnedMachines/Details/5 + public async Task Details(long? id) + { + if(id == null) return NotFound(); + + ProcessorsByMachineViewModel processorsByOwnedMachine = + await _context.ProcessorsByOwnedMachine.OrderBy(p => p.OwnedMachine.Machine.Name) + .ThenBy(p => p.Processor.Name).Select(p => new ProcessorsByMachineViewModel + { + Id = p.Id, + Machine = + $"{p.OwnedMachine.Machine.Company.Name} {p.OwnedMachine.Machine.Name} <{p.OwnedMachine.User.UserName}>", + Processor = p.Processor.Name, + Speed = p.Speed + }).FirstOrDefaultAsync(m => m.Id == id); + if(processorsByOwnedMachine == null) return NotFound(); + + return View(processorsByOwnedMachine); + } + + // GET: Admin/ProcessorsByOwnedMachines/Create + public IActionResult Create() + { + ViewData["OwnedMachineId"] = + new + SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}), + "Id", "Name"); + ViewData["ProcessorId"] = new SelectList(_context.Processors, "Id", "Name"); + return View(); + } + + // POST: Admin/ProcessorsByOwnedMachines/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("ProcessorId,OwnedMachineId,Speed,Id")] + ProcessorsByOwnedMachine processorsByOwnedMachine) + { + if(ModelState.IsValid) + { + _context.Add(processorsByOwnedMachine); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + ViewData["OwnedMachineId"] = + new + SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}), + "Id", "Name", processorsByOwnedMachine.OwnedMachineId); + ViewData["ProcessorId"] = + new SelectList(_context.Processors, "Id", "Name", processorsByOwnedMachine.ProcessorId); + return View(processorsByOwnedMachine); + } + + // GET: Admin/ProcessorsByOwnedMachines/Edit/5 + public async Task Edit(long? id) + { + if(id == null) return NotFound(); + + ProcessorsByOwnedMachine processorsByOwnedMachine = await _context.ProcessorsByOwnedMachine.FindAsync(id); + if(processorsByOwnedMachine == null) return NotFound(); + + ViewData["OwnedMachineId"] = + new + SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}), + "Id", "Name", processorsByOwnedMachine.OwnedMachineId); + ViewData["ProcessorId"] = + new SelectList(_context.Processors, "Id", "Name", processorsByOwnedMachine.ProcessorId); + return View(processorsByOwnedMachine); + } + + // POST: Admin/ProcessorsByOwnedMachines/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("ProcessorId,OwnedMachineId,Speed,Id")] + ProcessorsByOwnedMachine processorsByOwnedMachine) + { + if(id != processorsByOwnedMachine.Id) return NotFound(); + + if(ModelState.IsValid) + { + try + { + _context.Update(processorsByOwnedMachine); + await _context.SaveChangesAsync(); + } + catch(DbUpdateConcurrencyException) + { + if(!ProcessorsByOwnedMachineExists(processorsByOwnedMachine.Id)) return NotFound(); + + throw; + } + + return RedirectToAction(nameof(Index)); + } + + ViewData["OwnedMachineId"] = + new + SelectList(_context.OwnedMachines.OrderBy(m => m.Machine.Company.Name).ThenBy(m => m.Machine.Name).ThenBy(m => m.User.UserName).Select(m => new {m.Id, Name = $"{m.Machine.Company.Name} {m.Machine.Name} <{m.User.UserName}>"}), + "Id", "Name", processorsByOwnedMachine.OwnedMachineId); + ViewData["ProcessorId"] = + new SelectList(_context.Processors, "Id", "Name", processorsByOwnedMachine.ProcessorId); + return View(processorsByOwnedMachine); + } + + // GET: Admin/ProcessorsByOwnedMachines/Delete/5 + public async Task Delete(long? id) + { + if(id == null) return NotFound(); + + ProcessorsByMachineViewModel processorsByOwnedMachine = + await _context.ProcessorsByOwnedMachine.OrderBy(p => p.OwnedMachine.Machine.Name) + .ThenBy(p => p.Processor.Name).Select(p => new ProcessorsByMachineViewModel + { + Id = p.Id, + Machine = + $"{p.OwnedMachine.Machine.Company.Name} {p.OwnedMachine.Machine.Name} <{p.OwnedMachine.User.UserName}>", + Processor = p.Processor.Name, + Speed = p.Speed + }).FirstOrDefaultAsync(m => m.Id == id); + if(processorsByOwnedMachine == null) return NotFound(); + + return View(processorsByOwnedMachine); + } + + // POST: Admin/ProcessorsByOwnedMachines/Delete/5 + [HttpPost] + [ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + ProcessorsByOwnedMachine processorsByOwnedMachine = await _context.ProcessorsByOwnedMachine.FindAsync(id); + _context.ProcessorsByOwnedMachine.Remove(processorsByOwnedMachine); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + bool ProcessorsByOwnedMachineExists(long id) + { + return _context.ProcessorsByOwnedMachine.Any(e => e.Id == id); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Create.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Create.cshtml new file mode 100644 index 00000000..f10bb6d7 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Create.cshtml @@ -0,0 +1,91 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Create.cshtml +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Admin view create +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model Cicm.Database.Models.ProcessorsByOwnedMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Processor by machine

+
+
+
+
+
+
+
+ + +
+
+ + +
+
+ + + + +
+ +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Delete.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Delete.cshtml new file mode 100644 index 00000000..7521d72a --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Delete.cshtml @@ -0,0 +1,76 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Delete.cshtml +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Admin view delete +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model cicm_web.Areas.Admin.Models.ProcessorsByMachineViewModel + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Processors by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ @Html.DisplayNameFor(model => model.Processor) +
+
+ @Html.DisplayFor(model => model.Processor) +
+
+ @Html.DisplayNameFor(model => model.Speed) +
+
+ @Html.DisplayFor(model => model.Speed) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Details.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Details.cshtml new file mode 100644 index 00000000..7c74d189 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Details.cshtml @@ -0,0 +1,74 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Details.cshtml +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Admin view details +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model cicm_web.Areas.Admin.Models.ProcessorsByMachineViewModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Processors by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ @Html.DisplayNameFor(model => model.Processor) +
+
+ @Html.DisplayFor(model => model.Processor) +
+
+ @Html.DisplayNameFor(model => model.Speed) +
+
+ @Html.DisplayFor(model => model.Speed) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Edit.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Edit.cshtml new file mode 100644 index 00000000..5e820019 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Edit.cshtml @@ -0,0 +1,99 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Edit.cshtml +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Admin view edit +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model Cicm.Database.Models.ProcessorsByOwnedMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Processors by machine

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+ + +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Index.cshtml b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Index.cshtml new file mode 100644 index 00000000..8748d8f4 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/ProcessorsByOwnedMachines/Index.cshtml @@ -0,0 +1,95 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Index.cshtml +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Admin view index +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@using cicm_web.Areas.Admin.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Processors by machine (Admin)"; +} + +

Processors by machine

+ +

+ + Create New + +

+ + + + + + + + + + + @foreach(ProcessorsByMachineViewModel item in Model) + { + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Machine) + + @Html.DisplayNameFor(model => model.Processor) + + @Html.DisplayNameFor(model => model.Speed) +
+ @Html.DisplayFor(modelItem => item.Machine) + + @Html.DisplayFor(modelItem => item.Processor) + + @Html.DisplayFor(modelItem => item.Speed) + + + Details + + + Edit + + + Delete + +
\ No newline at end of file