Add CRUD pages for owned machines.

This commit is contained in:
2019-05-29 23:09:20 +01:00
parent 3813ad80cf
commit b9a8c7e832
8 changed files with 559 additions and 1 deletions

View File

@@ -0,0 +1,160 @@
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;
namespace cicm_web.Areas.Admin.Controllers
{
[Area("Admin")]
[Authorize]
public class OwnedMachineController : Controller
{
private readonly cicmContext _context;
public OwnedMachineController(cicmContext context)
{
_context = context;
}
// GET: OwnedMachine
public async Task<IActionResult> Index()
{
var cicmContext = _context.OwnedMachines.Include(o => o.Machine);
return View(await cicmContext.ToListAsync());
}
// GET: OwnedMachine/Details/5
public async Task<IActionResult> Details(long? id)
{
if (id == null)
{
return NotFound();
}
var ownedMachine = await _context.OwnedMachines
.Include(o => o.Machine)
.FirstOrDefaultAsync(m => m.Id == id);
if (ownedMachine == null)
{
return NotFound();
}
return View(ownedMachine);
}
// GET: OwnedMachine/Create
public IActionResult Create()
{
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name");
return View();
}
// POST: OwnedMachine/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("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine)
{
if (ModelState.IsValid)
{
_context.Add(ownedMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
return View(ownedMachine);
}
// GET: OwnedMachine/Edit/5
public async Task<IActionResult> Edit(long? id)
{
if (id == null)
{
return NotFound();
}
var ownedMachine = await _context.OwnedMachines.FindAsync(id);
if (ownedMachine == null)
{
return NotFound();
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
return View(ownedMachine);
}
// POST: OwnedMachine/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("AcquisitionDate,LostDate,Status,LastStatusDate,Trade,Boxed,Manuals,SerialNumber,SerialNumberVisible,MachineId,Id")] OwnedMachine ownedMachine)
{
if (id != ownedMachine.Id)
{
return NotFound();
}
if (ModelState.IsValid)
{
try
{
_context.Update(ownedMachine);
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!OwnedMachineExists(ownedMachine.Id))
{
return NotFound();
}
else
{
throw;
}
}
return RedirectToAction(nameof(Index));
}
ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", ownedMachine.MachineId);
return View(ownedMachine);
}
// GET: OwnedMachine/Delete/5
public async Task<IActionResult> Delete(long? id)
{
if (id == null)
{
return NotFound();
}
var ownedMachine = await _context.OwnedMachines
.Include(o => o.Machine)
.FirstOrDefaultAsync(m => m.Id == id);
if (ownedMachine == null)
{
return NotFound();
}
return View(ownedMachine);
}
// POST: OwnedMachine/Delete/5
[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(long id)
{
var ownedMachine = await _context.OwnedMachines.FindAsync(id);
_context.OwnedMachines.Remove(ownedMachine);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
private bool OwnedMachineExists(long id)
{
return _context.OwnedMachines.Any(e => e.Id == id);
}
}
}

View File

@@ -60,6 +60,11 @@
<a asp-controller="StorageByMachines">Storage by machines</a><br /> <a asp-controller="StorageByMachines">Storage by machines</a><br />
</div> </div>
<div class="content">
<h3>Administrative pages for owned machines</h3>
<a asp-controller="OwnedMachine">Machines</a><br />
</div>
<div class="content"> <div class="content">
<h3>User administrative pages</h3> <h3>User administrative pages</h3>
@* TODO *@ To be implemented @* TODO *@ To be implemented

View File

@@ -0,0 +1,69 @@
@model Cicm.Database.Models.OwnedMachine
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>OwnedMachine</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="AcquisitionDate" class="control-label"></label>
<input asp-for="AcquisitionDate" class="form-control" />
<span asp-validation-for="AcquisitionDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LostDate" class="control-label"></label>
<input asp-for="LostDate" class="form-control" />
<span asp-validation-for="LostDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Status" class="control-label"></label>
<select asp-for="Status" class="form-control"></select>
<span asp-validation-for="Status" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LastStatusDate" class="control-label"></label>
<input asp-for="LastStatusDate" class="form-control" />
<span asp-validation-for="LastStatusDate" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Trade" /> @Html.DisplayNameFor(model => model.Trade)
</label>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Boxed" /> @Html.DisplayNameFor(model => model.Boxed)
</label>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Manuals" /> @Html.DisplayNameFor(model => model.Manuals)
</label>
</div>
<div class="form-group">
<label asp-for="SerialNumber" class="control-label"></label>
<input asp-for="SerialNumber" class="form-control" />
<span asp-validation-for="SerialNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="MachineId" class="control-label"></label>
<select asp-for="MachineId" class ="form-control" asp-items="ViewBag.MachineId"></select>
</div>
<div class="form-group">
<input type="submit" value="Create" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>

View File

@@ -0,0 +1,81 @@
@model Cicm.Database.Models.OwnedMachine
@{
ViewData["Title"] = "Delete";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>OwnedMachine</h4>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.AcquisitionDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.AcquisitionDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LostDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LostDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Status)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Status)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LastStatusDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LastStatusDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Trade)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Trade)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Boxed)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Boxed)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Manuals)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Manuals)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.SerialNumber)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.SerialNumber)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.SerialNumberVisible)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.SerialNumberVisible)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name)
</dd class>
</dl>
<form asp-action="Delete">
<input type="hidden" asp-for="Id" />
<input type="submit" value="Delete" class="btn btn-danger" /> |
<a asp-action="Index">Back to List</a>
</form>
</div>

View File

@@ -0,0 +1,78 @@
@model Cicm.Database.Models.OwnedMachine
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>OwnedMachine</h4>
<hr />
<dl class="row">
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.AcquisitionDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.AcquisitionDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LostDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LostDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Status)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Status)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.LastStatusDate)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.LastStatusDate)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Trade)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Trade)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Boxed)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Boxed)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Manuals)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Manuals)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.SerialNumber)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.SerialNumber)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.SerialNumberVisible)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.SerialNumberVisible)
</dd>
<dt class = "col-sm-2">
@Html.DisplayNameFor(model => model.Machine)
</dt>
<dd class = "col-sm-10">
@Html.DisplayFor(model => model.Machine.Name)
</dd>
</dl>
</div>
<div>
<a asp-action="Edit" asp-route-id="@Model.Id">Edit</a> |
<a asp-action="Index">Back to List</a>
</div>

View File

@@ -0,0 +1,76 @@
@model Cicm.Database.Models.OwnedMachine
@{
ViewData["Title"] = "Edit";
}
<h1>Edit</h1>
<h4>OwnedMachine</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="AcquisitionDate" class="control-label"></label>
<input asp-for="AcquisitionDate" class="form-control" />
<span asp-validation-for="AcquisitionDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LostDate" class="control-label"></label>
<input asp-for="LostDate" class="form-control" />
<span asp-validation-for="LostDate" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Status" class="control-label"></label>
<select asp-for="Status" class="form-control"></select>
<span asp-validation-for="Status" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="LastStatusDate" class="control-label"></label>
<input asp-for="LastStatusDate" class="form-control" />
<span asp-validation-for="LastStatusDate" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Trade" /> @Html.DisplayNameFor(model => model.Trade)
</label>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Boxed" /> @Html.DisplayNameFor(model => model.Boxed)
</label>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Manuals" /> @Html.DisplayNameFor(model => model.Manuals)
</label>
</div>
<div class="form-group">
<label asp-for="SerialNumber" class="control-label"></label>
<input asp-for="SerialNumber" class="form-control" />
<span asp-validation-for="SerialNumber" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="SerialNumberVisible" /> @Html.DisplayNameFor(model => model.SerialNumberVisible)
</label>
</div>
<div class="form-group">
<label asp-for="MachineId" class="control-label"></label>
<select asp-for="MachineId" class="form-control" asp-items="ViewBag.MachineId"></select>
<span asp-validation-for="MachineId" class="text-danger"></span>
</div>
<input type="hidden" asp-for="Id" />
<div class="form-group">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</form>
</div>
</div>
<div>
<a asp-action="Index">Back to List</a>
</div>

View File

@@ -0,0 +1,89 @@
@model IEnumerable<Cicm.Database.Models.OwnedMachine>
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<p>
<a asp-action="Create">Create New</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.AcquisitionDate)
</th>
<th>
@Html.DisplayNameFor(model => model.LostDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Status)
</th>
<th>
@Html.DisplayNameFor(model => model.LastStatusDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Trade)
</th>
<th>
@Html.DisplayNameFor(model => model.Boxed)
</th>
<th>
@Html.DisplayNameFor(model => model.Manuals)
</th>
<th>
@Html.DisplayNameFor(model => model.SerialNumber)
</th>
<th>
@Html.DisplayNameFor(model => model.SerialNumberVisible)
</th>
<th>
@Html.DisplayNameFor(model => model.Machine)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.AcquisitionDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.LostDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Status)
</td>
<td>
@Html.DisplayFor(modelItem => item.LastStatusDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Trade)
</td>
<td>
@Html.DisplayFor(modelItem => item.Boxed)
</td>
<td>
@Html.DisplayFor(modelItem => item.Manuals)
</td>
<td>
@Html.DisplayFor(modelItem => item.SerialNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.SerialNumberVisible)
</td>
<td>
@Html.DisplayFor(modelItem => item.Machine.Name)
</td>
<td>
<a asp-action="Edit" asp-route-id="@item.Id">Edit</a> |
<a asp-action="Details" asp-route-id="@item.Id">Details</a> |
<a asp-action="Delete" asp-route-id="@item.Id">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.674</Version> <Version>3.0.99.676</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>