diff --git a/Cicm.Database/Models/License.cs b/Cicm.Database/Models/License.cs index 7392b3e7..050c0aec 100644 --- a/Cicm.Database/Models/License.cs +++ b/Cicm.Database/Models/License.cs @@ -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 Photos { get; set; } } diff --git a/cicm_web/Areas/Admin/Controllers/LicensesController.cs b/cicm_web/Areas/Admin/Controllers/LicensesController.cs new file mode 100644 index 00000000..fa99f512 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/LicensesController.cs @@ -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 Index() + { + return View(await _context.Licenses.OrderBy(l => l.Name).ToListAsync()); + } + + // GET: Licenses/Details/5 + public async Task 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 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 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 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 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 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); + } + } +} \ 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 f6709f29..a550befd 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -45,6 +45,7 @@ Instruction sets
Instruction set extensions
Instruction set extensions by processor
+ Licenses
Machine families
Machines
Machine photos
diff --git a/cicm_web/Areas/Admin/Views/Licenses/Create.cshtml b/cicm_web/Areas/Admin/Views/Licenses/Create.cshtml new file mode 100644 index 00000000..3a416bdc --- /dev/null +++ b/cicm_web/Areas/Admin/Views/Licenses/Create.cshtml @@ -0,0 +1,79 @@ +@model Cicm.Database.Models.License + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

License

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

Delete

+ +

Are you sure you want to delete this?

+
+

License

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.SPDX) +
+
+ @Html.DisplayFor(model => model.SPDX) +
+
+ @Html.DisplayNameFor(model => model.FsfApproved) +
+
+ @Html.DisplayFor(model => model.FsfApproved) +
+
+ @Html.DisplayNameFor(model => model.OsiApproved) +
+
+ @Html.DisplayFor(model => model.OsiApproved) +
+
+ @Html.DisplayNameFor(model => model.Link) +
+
+ @Html.DisplayFor(model => model.Link) +
+
+ @Html.DisplayNameFor(model => model.Text) +
+
+ @Html.DisplayFor(model => model.Text) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Licenses/Details.cshtml b/cicm_web/Areas/Admin/Views/Licenses/Details.cshtml new file mode 100644 index 00000000..8f6b1797 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/Licenses/Details.cshtml @@ -0,0 +1,61 @@ +@model Cicm.Database.Models.License + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

License

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.SPDX) +
+
+ @Html.DisplayFor(model => model.SPDX) +
+
+ @Html.DisplayNameFor(model => model.FsfApproved) +
+
+ @Html.DisplayFor(model => model.FsfApproved) +
+
+ @Html.DisplayNameFor(model => model.OsiApproved) +
+
+ @Html.DisplayFor(model => model.OsiApproved) +
+
+ @Html.DisplayNameFor(model => model.Link) +
+
+ @Html.DisplayFor(model => model.Link) +
+
+ @Html.DisplayNameFor(model => model.Text) +
+
+ @Html.DisplayFor(model => model.Text) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Licenses/Edit.cshtml b/cicm_web/Areas/Admin/Views/Licenses/Edit.cshtml new file mode 100644 index 00000000..0bac9ab3 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/Licenses/Edit.cshtml @@ -0,0 +1,81 @@ +@model Cicm.Database.Models.License + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

License

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

Licenses

+ +

+ + Create New + +

+ + + + + + + + + + + + + @foreach(License item in Model) + { + + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Name) + + @Html.DisplayNameFor(model => model.SPDX) + + @Html.DisplayNameFor(model => model.FsfApproved) + + @Html.DisplayNameFor(model => model.OsiApproved) + + @Html.DisplayNameFor(model => model.Link) +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.SPDX) + + @Html.DisplayFor(modelItem => item.FsfApproved) + + @Html.DisplayFor(modelItem => item.OsiApproved) + + @if(item.Link != null) + { + + Link + + } + + + Details + + + Edit + + + Delete + +
\ No newline at end of file diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index f6e2e0b5..c20e2345 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.597 + 3.0.99.603 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website