Implement processor by owned machine admin pages.

This commit is contained in:
2019-05-31 00:44:11 +01:00
parent 30eadea7d8
commit 4caf531735
6 changed files with 650 additions and 0 deletions

View File

@@ -0,0 +1,215 @@
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : ProcessorsByOwnedMachinesController.cs
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// 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<IActionResult> Index()
{
IIncludableQueryable<ProcessorsByOwnedMachine, Processor> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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);
}
}
}

View File

@@ -0,0 +1,91 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Create.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
}
@model Cicm.Database.Models.ProcessorsByOwnedMachine
@{
ViewData["Title"] = "Create";
}
<h2>Create</h2>
<h4>Processor by machine</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="OwnedMachine"
class="control-label">
</label>
<select asp-for="OwnedMachine"
class="form-control"
asp-items="ViewBag.OwnedMachineId">
</select>
</div>
<div class="form-group">
<label asp-for="ProcessorId"
class="control-label">
</label>
<select asp-for="ProcessorId"
class="form-control"
asp-items="ViewBag.ProcessorId">
</select>
</div>
<div class="form-group">
<label asp-for="Speed"
class="control-label">
</label>
<input asp-for="Speed"
class="form-control" />
<span asp-validation-for="Speed"
class="text-danger">
</span>
</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>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}

View File

@@ -0,0 +1,76 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Delete.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
}
@model cicm_web.Areas.Admin.Models.ProcessorsByMachineViewModel
@{
ViewData["Title"] = "Delete";
}
<h2>Delete</h2>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>Processors by machine</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd>
@Html.DisplayFor(model => model.Machine)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Processor)
</dt>
<dd>
@Html.DisplayFor(model => model.Processor)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Speed)
</dt>
<dd>
@Html.DisplayFor(model => model.Speed)
</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,74 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Details.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
}
@model cicm_web.Areas.Admin.Models.ProcessorsByMachineViewModel
@{
ViewData["Title"] = "Details";
}
<h2>Details</h2>
<div>
<h4>Processors by machine</h4>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd>
@Html.DisplayFor(model => model.Machine)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Processor)
</dt>
<dd>
@Html.DisplayFor(model => model.Processor)
</dd>
<dt>
@Html.DisplayNameFor(model => model.Speed)
</dt>
<dd>
@Html.DisplayFor(model => model.Speed)
</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,99 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Edit.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
}
@model Cicm.Database.Models.ProcessorsByOwnedMachine
@{
ViewData["Title"] = "Edit";
}
<h2>Edit</h2>
<h4>Processors by machine</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="OwnedMachine"
class="control-label">
</label>
<select asp-for="OwnedMachineId"
class="form-control"
asp-items="ViewBag.OwnedMachineId">
</select>
<span asp-validation-for="OwnedMachineId"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Processor"
class="control-label">
</label>
<select asp-for="ProcessorId"
class="form-control"
asp-items="ViewBag.ProcessorId">
</select>
<span asp-validation-for="ProcessorId"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Speed"
class="control-label">
</label>
<input asp-for="Speed"
class="form-control" />
<span asp-validation-for="Speed"
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>
@section Scripts {
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
}

View File

@@ -0,0 +1,95 @@
@{
/******************************************************************************
// Canary Islands Computer Museum Website
// ----------------------------------------------------------------------------
//
// Filename : Index.cshtml
// Author(s) : Natalia Portillo <claunia@claunia.com>
//
// --[ 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 <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------
// Copyright © 2003-2018 Natalia Portillo
*******************************************************************************/
}
@using cicm_web.Areas.Admin.Models
@model IEnumerable<cicm_web.Areas.Admin.Models.ProcessorsByMachineViewModel>
@{
ViewData["Title"] = "Processors by machine (Admin)";
}
<h2>Processors by machine</h2>
<p>
<a asp-action="Create"
class="btn btn-primary">
Create New
</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Machine)
</th>
<th>
@Html.DisplayNameFor(model => model.Processor)
</th>
<th>
@Html.DisplayNameFor(model => model.Speed)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(ProcessorsByMachineViewModel item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Machine)
</td>
<td>
@Html.DisplayFor(modelItem => item.Processor)
</td>
<td>
@Html.DisplayFor(modelItem => item.Speed)
</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>