Scaffold CRUD pages for licenses.

This commit is contained in:
2019-05-27 18:48:47 +01:00
parent 574176ee4c
commit 9bed89f390
9 changed files with 498 additions and 1 deletions

View File

@@ -19,10 +19,12 @@ namespace Cicm.Database.Models
public bool OsiApproved { get; set; }
[DisplayName("License text link")]
[StringLength(512)]
[Url]
public string Link { get; set; }
[DisplayName("License text")]
[Column(TypeName = "longtext")]
[StringLength(131072)]
[DataType(DataType.MultilineText)]
public string Text { get; set; }
public virtual ICollection<MachinePhoto> Photos { get; set; }
}

View File

@@ -0,0 +1,128 @@
using System.Linq;
using System.Threading.Tasks;
using Cicm.Database.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
namespace cicm_web
{
[Area("Admin")]
[Authorize]
public class LicensesController : Controller
{
readonly cicmContext _context;
public LicensesController(cicmContext context)
{
_context = context;
}
// GET: Licenses
public async Task<IActionResult> Index()
{
return View(await _context.Licenses.OrderBy(l => l.Name).ToListAsync());
}
// GET: Licenses/Details/5
public async Task<IActionResult> Details(int? id)
{
if(id == null) return NotFound();
License license = await _context.Licenses.FirstOrDefaultAsync(m => m.Id == id);
if(license == null) return NotFound();
return View(license);
}
// GET: Licenses/Create
public IActionResult Create() => View();
// POST: Licenses/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("Name,SPDX,FsfApproved,OsiApproved,Link,Text,Id")]
License license)
{
if(ModelState.IsValid)
{
_context.Add(license);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
return View(license);
}
// GET: Licenses/Edit/5
public async Task<IActionResult> Edit(int? id)
{
if(id == null) return NotFound();
License license = await _context.Licenses.FindAsync(id);
if(license == null) return NotFound();
return View(license);
}
// POST: Licenses/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(int id, [Bind("Name,SPDX,FsfApproved,OsiApproved,Link,Text,Id")]
License license)
{
if(id != license.Id) return NotFound();
if(ModelState.IsValid)
{
try
{
_context.Update(license);
await _context.SaveChangesAsync();
}
catch(DbUpdateConcurrencyException)
{
if(!LicenseExists(license.Id)) return NotFound();
throw;
}
return RedirectToAction(nameof(Index));
}
return View(license);
}
// GET: Licenses/Delete/5
public async Task<IActionResult> Delete(int? id)
{
if(id == null) return NotFound();
License license = await _context.Licenses.FirstOrDefaultAsync(m => m.Id == id);
if(license == null) return NotFound();
return View(license);
}
// POST: Licenses/Delete/5
[HttpPost]
[ActionName("Delete")]
[ValidateAntiForgeryToken]
public async Task<IActionResult> DeleteConfirmed(int id)
{
License license = await _context.Licenses.FindAsync(id);
_context.Licenses.Remove(license);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(Index));
}
bool LicenseExists(int id)
{
return _context.Licenses.Any(e => e.Id == id);
}
}
}

View File

@@ -45,6 +45,7 @@
<a asp-controller="InstructionSets">Instruction sets</a><br />
<a asp-controller="InstructionSetExtensions">Instruction set extensions</a><br />
<a asp-controller="InstructionSetExtensionsByProcessor">Instruction set extensions by processor</a><br />
<a asp-controller="Licenses">Licenses</a><br />
<a asp-controller="MachineFamilies">Machine families</a><br />
<a asp-controller="Machines">Machines</a><br />
<a asp-controller="MachinePhotos">Machine photos</a><br />

View File

@@ -0,0 +1,79 @@
@model Cicm.Database.Models.License
@{
ViewData["Title"] = "Create";
}
<h1>Create</h1>
<h4>License</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="Name"
class="control-label">
</label>
<input asp-for="Name"
class="form-control" />
<span asp-validation-for="Name"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="SPDX"
class="control-label">
</label>
<input asp-for="SPDX"
class="form-control" />
<span asp-validation-for="SPDX"
class="text-danger">
</span>
</div>
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input"
asp-for="FsfApproved" /> @Html.DisplayNameFor(model => model.FsfApproved)
</label>
</div>
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input"
asp-for="OsiApproved" /> @Html.DisplayNameFor(model => model.OsiApproved)
</label>
</div>
<div class="form-group">
<label asp-for="Link"
class="control-label">
</label>
<input asp-for="Link"
class="form-control" />
<span asp-validation-for="Link"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Text"
class="control-label">
</label>
<textarea asp-for="Text" class="form-control" ></textarea>
<span asp-validation-for="Text"
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>

View File

@@ -0,0 +1,63 @@
@model Cicm.Database.Models.License
@{
ViewData["Title"] = "Delete";
}
<h1>Delete</h1>
<h3>Are you sure you want to delete this?</h3>
<div>
<h4>License</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.SPDX)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.SPDX)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.FsfApproved)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.FsfApproved)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.OsiApproved)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.OsiApproved)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Link)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Link)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Text)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Text)
</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,61 @@
@model Cicm.Database.Models.License
@{
ViewData["Title"] = "Details";
}
<h1>Details</h1>
<div>
<h4>License</h4>
<hr />
<dl class="row">
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Name)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Name)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.SPDX)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.SPDX)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.FsfApproved)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.FsfApproved)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.OsiApproved)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.OsiApproved)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Link)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Link)
</dd>
<dt class="col-sm-2">
@Html.DisplayNameFor(model => model.Text)
</dt>
<dd class="col-sm-10">
@Html.DisplayFor(model => model.Text)
</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,81 @@
@model Cicm.Database.Models.License
@{
ViewData["Title"] = "Edit";
}
<h1>Edit</h1>
<h4>License</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="Name"
class="control-label">
</label>
<input asp-for="Name"
class="form-control" />
<span asp-validation-for="Name"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="SPDX"
class="control-label">
</label>
<input asp-for="SPDX"
class="form-control" />
<span asp-validation-for="SPDX"
class="text-danger">
</span>
</div>
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input"
asp-for="FsfApproved" /> @Html.DisplayNameFor(model => model.FsfApproved)
</label>
</div>
<div class="form-check form-group">
<label class="form-check-label">
<input class="form-check-input"
asp-for="OsiApproved" /> @Html.DisplayNameFor(model => model.OsiApproved)
</label>
</div>
<div class="form-group">
<label asp-for="Link"
class="control-label">
</label>
<input asp-for="Link"
class="form-control" />
<span asp-validation-for="Link"
class="text-danger">
</span>
</div>
<div class="form-group">
<label asp-for="Text"
class="control-label">
</label>
<textarea asp-for="Text" class="form-control"></textarea>
<span asp-validation-for="Text"
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,82 @@
@using Cicm.Database.Models
@model IEnumerable<Cicm.Database.Models.License>
@{
ViewData["Title"] = "Index";
}
<h1>Licenses</h1>
<p>
<a asp-action="Create"
class="btn btn-primary">
Create New
</a>
</p>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.SPDX)
</th>
<th>
@Html.DisplayNameFor(model => model.FsfApproved)
</th>
<th>
@Html.DisplayNameFor(model => model.OsiApproved)
</th>
<th>
@Html.DisplayNameFor(model => model.Link)
</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach(License item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.SPDX)
</td>
<td>
@Html.DisplayFor(modelItem => item.FsfApproved)
</td>
<td>
@Html.DisplayFor(modelItem => item.OsiApproved)
</td>
<td>
@if(item.Link != null)
{
<a href="@item.Link"
target="_blank">
Link
</a>
}
</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">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>3.0.99.597</Version>
<Version>3.0.99.603</Version>
<Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2018 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product>