diff --git a/cicm_web/Areas/Admin/Controllers/MemoryByOwnedMachinesController.cs b/cicm_web/Areas/Admin/Controllers/MemoryByOwnedMachinesController.cs new file mode 100644 index 00000000..87a64aec --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/MemoryByOwnedMachinesController.cs @@ -0,0 +1,213 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : MemoryByOwnedMachinesController.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Memory by machines 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 . +// +// ---------------------------------------------------------------------------- +// 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 MemoryByOwnedMachinesController : Controller + { + readonly cicmContext _context; + + public MemoryByOwnedMachinesController(cicmContext context) + { + _context = context; + } + + // GET: Admin/MemoryByOwnedMachines + public async Task Index() + { + IIncludableQueryable cicmContext = + _context.MemoryByOwnedMachine.Include(m => m.OwnedMachine); + return View(await cicmContext.OrderBy(m => m.OwnedMachine.Machine.Company.Name) + .ThenBy(m => m.OwnedMachine.Machine.Name) + .ThenBy(m => m.OwnedMachine.User.UserName).ThenBy(m => m.Usage) + .ThenBy(m => m.Size).ThenBy(m => m.Type) + .Select(m => new MemoryByMachineViewModel + { + Id = m.Id, + Machine = + $"{m.OwnedMachine.Machine.Company.Name} {m.OwnedMachine.Machine.Name} <{m.OwnedMachine.User.UserName}>", + Size = m.Size, + Speed = m.Speed, + Type = m.Type, + Usage = m.Usage + }).ToListAsync()); + } + + // GET: Admin/MemoryByOwnedMachines/Details/5 + public async Task Details(long? id) + { + if(id == null) return NotFound(); + + IIncludableQueryable cicmContext = + _context.MemoryByOwnedMachine.Include(m => m.OwnedMachine); + MemoryByMachineViewModel memoryByOwnedMachine = await cicmContext + .OrderBy(m => m.OwnedMachine.Machine.Company.Name) + .ThenBy(m => m.OwnedMachine.Machine.Name) + .ThenBy(m => m.OwnedMachine.User.UserName) + .ThenBy(m => m.Usage).ThenBy(m => m.Size) + .ThenBy(m => m.Type) + .Select(m => new MemoryByMachineViewModel + { + Id = m.Id, + Machine = + $"{m.OwnedMachine.Machine.Company.Name} {m.OwnedMachine.Machine.Name} <{m.OwnedMachine.User.UserName}>", + Size = m.Size, + Speed = m.Speed, + Type = m.Type, + Usage = m.Usage + }).FirstOrDefaultAsync(m => m.Id == id); + if(memoryByOwnedMachine == null) return NotFound(); + + return View(memoryByOwnedMachine); + } + + // GET: Admin/MemoryByOwnedMachines/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"); + return View(); + } + + // POST: Admin/MemoryByOwnedMachines/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("OwnedMachineId,Type,Usage,Size,Speed,Id")] + MemoryByOwnedMachine memoryByOwnedMachine) + { + if(ModelState.IsValid) + { + _context.Add(memoryByOwnedMachine); + 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", memoryByOwnedMachine.OwnedMachineId); + return View(memoryByOwnedMachine); + } + + // GET: Admin/MemoryByOwnedMachines/Edit/5 + public async Task Edit(long? id) + { + if(id == null) return NotFound(); + + MemoryByOwnedMachine memoryByOwnedMachine = await _context.MemoryByOwnedMachine.FindAsync(id); + if(memoryByOwnedMachine == 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", memoryByOwnedMachine.OwnedMachineId); + return View(memoryByOwnedMachine); + } + + // POST: Admin/MemoryByOwnedMachines/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("OwnedMachineId,Type,Usage,Size,Speed,Id")] + MemoryByOwnedMachine memoryByOwnedMachine) + { + if(id != memoryByOwnedMachine.Id) return NotFound(); + + if(ModelState.IsValid) + { + try + { + _context.Update(memoryByOwnedMachine); + await _context.SaveChangesAsync(); + } + catch(DbUpdateConcurrencyException) + { + if(!MemoryByOwnedMachineExists(memoryByOwnedMachine.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", memoryByOwnedMachine.OwnedMachineId); + return View(memoryByOwnedMachine); + } + + // GET: Admin/MemoryByOwnedMachines/Delete/5 + public async Task Delete(long? id) + { + if(id == null) return NotFound(); + + MemoryByOwnedMachine memoryByOwnedMachine = + await _context.MemoryByOwnedMachine.Include(m => m.OwnedMachine).FirstOrDefaultAsync(m => m.Id == id); + if(memoryByOwnedMachine == null) return NotFound(); + + return View(memoryByOwnedMachine); + } + + // POST: Admin/MemoryByOwnedMachines/Delete/5 + [HttpPost] + [ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + MemoryByOwnedMachine memoryByOwnedMachine = await _context.MemoryByOwnedMachine.FindAsync(id); + _context.MemoryByOwnedMachine.Remove(memoryByOwnedMachine); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + bool MemoryByOwnedMachineExists(long id) + { + return _context.MemoryByOwnedMachine.Any(e => e.Id == id); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Create.cshtml b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Create.cshtml new file mode 100644 index 00000000..fee2e378 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Create.cshtml @@ -0,0 +1,117 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Create.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@using Cicm.Database +@model Cicm.Database.Models.MemoryByOwnedMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Memory by machine

+
+
+
+
+
+
+
+ + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+ +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Delete.cshtml b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Delete.cshtml new file mode 100644 index 00000000..872436a3 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Delete.cshtml @@ -0,0 +1,88 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Delete.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model Cicm.Database.Models.MemoryByOwnedMachine + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Memory by machine

+
+
+
+ @Html.DisplayNameFor(model => model.OwnedMachine) +
+
+ @Html.DisplayFor(model => model.OwnedMachine.Machine.Name) +
+
+ @Html.DisplayNameFor(model => model.Usage) +
+
+ @Html.DisplayFor(model => model.Usage) +
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+ @Html.DisplayNameFor(model => model.Size) +
+
+ @Html.DisplayFor(model => model.Size) +
+
+ @Html.DisplayNameFor(model => model.Speed) +
+
+ @Html.DisplayFor(model => model.Speed) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Details.cshtml b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Details.cshtml new file mode 100644 index 00000000..cd5ea3bc --- /dev/null +++ b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Details.cshtml @@ -0,0 +1,86 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Details.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@model cicm_web.Areas.Admin.Models.MemoryByMachineViewModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Memory by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ @Html.DisplayNameFor(model => model.Usage) +
+
+ @Html.DisplayFor(model => model.Usage) +
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+ @Html.DisplayNameFor(model => model.Size) +
+
+ @Html.DisplayFor(model => model.Size) +
+
+ @Html.DisplayNameFor(model => model.Speed) +
+
+ @Html.DisplayFor(model => model.Speed) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Edit.cshtml b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Edit.cshtml new file mode 100644 index 00000000..f96aed77 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Edit.cshtml @@ -0,0 +1,119 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Edit.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@using Cicm.Database +@model Cicm.Database.Models.MemoryByOwnedMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Memory by machine

+
+
+
+
+
+
+
+ + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+ + +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Index.cshtml b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Index.cshtml new file mode 100644 index 00000000..fe5e7666 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/MemoryByOwnedMachines/Index.cshtml @@ -0,0 +1,107 @@ +@{ + /****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : Index.cshtml +// Author(s) : Natalia Portillo +// +// --[ 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 . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ +} +@using cicm_web.Areas.Admin.Models +@model IEnumerable + +@{ + ViewData["Title"] = "Memory by machines (Admin)"; +} + +

Memory by machines

+ +

+ + Create New + +

+ + + + + + + + + + + + + @foreach(MemoryByMachineViewModel item in Model) + { + + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Machine) + + @Html.DisplayNameFor(model => model.Usage) + + @Html.DisplayNameFor(model => model.Type) + + @Html.DisplayNameFor(model => model.Size) + + @Html.DisplayNameFor(model => model.Speed) +
+ @Html.DisplayFor(modelItem => item.Machine) + + @Html.DisplayFor(modelItem => item.Usage) + + @Html.DisplayFor(modelItem => item.Type) + + @Html.DisplayFor(modelItem => item.Size) + + @Html.DisplayFor(modelItem => item.Speed) + + + Details + + + Edit + + + Delete + +
\ No newline at end of file