From b9a8c7e832460208c5616e401587aebd5ef1e16a Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 29 May 2019 23:09:20 +0100 Subject: [PATCH] Add CRUD pages for owned machines. --- .../Controllers/OwnedMachineController.cs | 160 ++++++++++++++++++ cicm_web/Areas/Admin/Views/Home/Index.cshtml | 5 + .../Admin/Views/OwnedMachine/Create.cshtml | 69 ++++++++ .../Admin/Views/OwnedMachine/Delete.cshtml | 81 +++++++++ .../Admin/Views/OwnedMachine/Details.cshtml | 78 +++++++++ .../Admin/Views/OwnedMachine/Edit.cshtml | 76 +++++++++ .../Admin/Views/OwnedMachine/Index.cshtml | 89 ++++++++++ cicm_web/cicm_web.csproj | 2 +- 8 files changed, 559 insertions(+), 1 deletion(-) create mode 100644 cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs create mode 100644 cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml create mode 100644 cicm_web/Areas/Admin/Views/OwnedMachine/Delete.cshtml create mode 100644 cicm_web/Areas/Admin/Views/OwnedMachine/Details.cshtml create mode 100644 cicm_web/Areas/Admin/Views/OwnedMachine/Edit.cshtml create mode 100644 cicm_web/Areas/Admin/Views/OwnedMachine/Index.cshtml diff --git a/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs b/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs new file mode 100644 index 00000000..2e50e3e0 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/OwnedMachineController.cs @@ -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 Index() + { + var cicmContext = _context.OwnedMachines.Include(o => o.Machine); + return View(await cicmContext.ToListAsync()); + } + + // GET: OwnedMachine/Details/5 + public async Task 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 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 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 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 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 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); + } + } +} diff --git a/cicm_web/Areas/Admin/Views/Home/Index.cshtml b/cicm_web/Areas/Admin/Views/Home/Index.cshtml index a550befd..ab5e6d79 100644 --- a/cicm_web/Areas/Admin/Views/Home/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Home/Index.cshtml @@ -60,6 +60,11 @@ Storage by machines
+
+

Administrative pages for owned machines

+ Machines
+
+

User administrative pages

@* TODO *@ To be implemented diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml new file mode 100644 index 00000000..52b96e24 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Create.cshtml @@ -0,0 +1,69 @@ +@model Cicm.Database.Models.OwnedMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

OwnedMachine

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+ + +
+
+ +
+
+
+
+ + + diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Delete.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Delete.cshtml new file mode 100644 index 00000000..4d5234be --- /dev/null +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Delete.cshtml @@ -0,0 +1,81 @@ +@model Cicm.Database.Models.OwnedMachine + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

OwnedMachine

+
+
+
+ @Html.DisplayNameFor(model => model.AcquisitionDate) +
+
+ @Html.DisplayFor(model => model.AcquisitionDate) +
+
+ @Html.DisplayNameFor(model => model.LostDate) +
+
+ @Html.DisplayFor(model => model.LostDate) +
+
+ @Html.DisplayNameFor(model => model.Status) +
+
+ @Html.DisplayFor(model => model.Status) +
+
+ @Html.DisplayNameFor(model => model.LastStatusDate) +
+
+ @Html.DisplayFor(model => model.LastStatusDate) +
+
+ @Html.DisplayNameFor(model => model.Trade) +
+
+ @Html.DisplayFor(model => model.Trade) +
+
+ @Html.DisplayNameFor(model => model.Boxed) +
+
+ @Html.DisplayFor(model => model.Boxed) +
+
+ @Html.DisplayNameFor(model => model.Manuals) +
+
+ @Html.DisplayFor(model => model.Manuals) +
+
+ @Html.DisplayNameFor(model => model.SerialNumber) +
+
+ @Html.DisplayFor(model => model.SerialNumber) +
+
+ @Html.DisplayNameFor(model => model.SerialNumberVisible) +
+
+ @Html.DisplayFor(model => model.SerialNumberVisible) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine.Name) +
+
+ +
+ + | + Back to List +
+
diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Details.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Details.cshtml new file mode 100644 index 00000000..3d4e7e14 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Details.cshtml @@ -0,0 +1,78 @@ +@model Cicm.Database.Models.OwnedMachine + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

OwnedMachine

+
+
+
+ @Html.DisplayNameFor(model => model.AcquisitionDate) +
+
+ @Html.DisplayFor(model => model.AcquisitionDate) +
+
+ @Html.DisplayNameFor(model => model.LostDate) +
+
+ @Html.DisplayFor(model => model.LostDate) +
+
+ @Html.DisplayNameFor(model => model.Status) +
+
+ @Html.DisplayFor(model => model.Status) +
+
+ @Html.DisplayNameFor(model => model.LastStatusDate) +
+
+ @Html.DisplayFor(model => model.LastStatusDate) +
+
+ @Html.DisplayNameFor(model => model.Trade) +
+
+ @Html.DisplayFor(model => model.Trade) +
+
+ @Html.DisplayNameFor(model => model.Boxed) +
+
+ @Html.DisplayFor(model => model.Boxed) +
+
+ @Html.DisplayNameFor(model => model.Manuals) +
+
+ @Html.DisplayFor(model => model.Manuals) +
+
+ @Html.DisplayNameFor(model => model.SerialNumber) +
+
+ @Html.DisplayFor(model => model.SerialNumber) +
+
+ @Html.DisplayNameFor(model => model.SerialNumberVisible) +
+
+ @Html.DisplayFor(model => model.SerialNumberVisible) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine.Name) +
+
+
+ diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Edit.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Edit.cshtml new file mode 100644 index 00000000..aa1c0eb2 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Edit.cshtml @@ -0,0 +1,76 @@ +@model Cicm.Database.Models.OwnedMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

OwnedMachine

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+ +
+
+ + + +
+ +
+ +
+
+
+
+ + + diff --git a/cicm_web/Areas/Admin/Views/OwnedMachine/Index.cshtml b/cicm_web/Areas/Admin/Views/OwnedMachine/Index.cshtml new file mode 100644 index 00000000..6281d1d1 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/OwnedMachine/Index.cshtml @@ -0,0 +1,89 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + + + + + + + + +@foreach (var item in Model) { + + + + + + + + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.AcquisitionDate) + + @Html.DisplayNameFor(model => model.LostDate) + + @Html.DisplayNameFor(model => model.Status) + + @Html.DisplayNameFor(model => model.LastStatusDate) + + @Html.DisplayNameFor(model => model.Trade) + + @Html.DisplayNameFor(model => model.Boxed) + + @Html.DisplayNameFor(model => model.Manuals) + + @Html.DisplayNameFor(model => model.SerialNumber) + + @Html.DisplayNameFor(model => model.SerialNumberVisible) + + @Html.DisplayNameFor(model => model.Machine) +
+ @Html.DisplayFor(modelItem => item.AcquisitionDate) + + @Html.DisplayFor(modelItem => item.LostDate) + + @Html.DisplayFor(modelItem => item.Status) + + @Html.DisplayFor(modelItem => item.LastStatusDate) + + @Html.DisplayFor(modelItem => item.Trade) + + @Html.DisplayFor(modelItem => item.Boxed) + + @Html.DisplayFor(modelItem => item.Manuals) + + @Html.DisplayFor(modelItem => item.SerialNumber) + + @Html.DisplayFor(modelItem => item.SerialNumberVisible) + + @Html.DisplayFor(modelItem => item.Machine.Name) + + Edit | + Details | + Delete +
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 0d1170e0..3c69c7bb 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.2 - 3.0.99.674 + 3.0.99.676 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website