diff --git a/cicm_web/Areas/Admin/Controllers/StorageByOwnedMachinesController.cs b/cicm_web/Areas/Admin/Controllers/StorageByOwnedMachinesController.cs new file mode 100644 index 00000000..5f6291b6 --- /dev/null +++ b/cicm_web/Areas/Admin/Controllers/StorageByOwnedMachinesController.cs @@ -0,0 +1,226 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : StorageByOwnedMachinesController.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Storage 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 StorageByOwnedMachinesController : Controller + { + readonly cicmContext _context; + + public StorageByOwnedMachinesController(cicmContext context) + { + _context = context; + } + + // GET: Admin/StorageByOwnedMachines + public async Task Index() + { + IIncludableQueryable cicmContext = + _context.StorageByOwnedMachine.Include(s => s.OwnedMachine); + return View(await cicmContext.OrderBy(s => s.OwnedMachine.Machine.Company.Name) + .ThenBy(s => s.OwnedMachine.Machine.Name) + .ThenBy(s => s.OwnedMachine.User.UserName) + .Select(s => new StorageByMachineViewModel + { + Id = s.Id, + Company = s.OwnedMachine.Machine.Company.Name, + Machine = + $"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>", + Type = s.Type, + Interface = s.Interface, + Capacity = s.Capacity + }).ToListAsync()); + } + + // GET: Admin/StorageByOwnedMachines/Details/5 + public async Task Details(long? id) + { + if(id == null) return NotFound(); + + StorageByMachineViewModel storageByOwnedMachine = await _context + .StorageByOwnedMachine + .OrderBy(s => s.OwnedMachine.Machine.Company.Name) + .ThenBy(s => s.OwnedMachine.Machine.Name) + .ThenBy(s => s.OwnedMachine.User.UserName) + .Select(s => new StorageByMachineViewModel + { + Id = s.Id, + Company = + s.OwnedMachine.Machine.Company + .Name, + Machine = + $"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>", + Type = s.Type, + Interface = s.Interface, + Capacity = s.Capacity + }).FirstOrDefaultAsync(m => m.Id == id); + if(storageByOwnedMachine == null) return NotFound(); + + return View(storageByOwnedMachine); + } + + // GET: Admin/StorageByOwnedMachines/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/StorageByOwnedMachines/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,Interface,Capacity,Id")] + StorageByOwnedMachine storageByOwnedMachine) + { + if(ModelState.IsValid) + { + _context.Add(storageByOwnedMachine); + 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", storageByOwnedMachine.OwnedMachineId); + return View(storageByOwnedMachine); + } + + // GET: Admin/StorageByOwnedMachines/Edit/5 + public async Task Edit(long? id) + { + if(id == null) return NotFound(); + + StorageByOwnedMachine storageByOwnedMachine = await _context.StorageByOwnedMachine.FindAsync(id); + if(storageByOwnedMachine == 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", storageByOwnedMachine.OwnedMachineId); + return View(storageByOwnedMachine); + } + + // POST: Admin/StorageByOwnedMachines/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,Interface,Capacity,Id")] + StorageByOwnedMachine storageByOwnedMachine) + { + if(id != storageByOwnedMachine.Id) return NotFound(); + + if(ModelState.IsValid) + { + try + { + _context.Update(storageByOwnedMachine); + await _context.SaveChangesAsync(); + } + catch(DbUpdateConcurrencyException) + { + if(!StorageByOwnedMachineExists(storageByOwnedMachine.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", storageByOwnedMachine.OwnedMachineId); + return View(storageByOwnedMachine); + } + + // GET: Admin/StorageByOwnedMachines/Delete/5 + public async Task Delete(long? id) + { + if(id == null) return NotFound(); + + StorageByMachineViewModel storageByOwnedMachine = await _context + .StorageByOwnedMachine + .OrderBy(s => s.OwnedMachine.Machine.Company.Name) + .ThenBy(s => s.OwnedMachine.Machine.Name) + .ThenBy(s => s.OwnedMachine.User.UserName) + .Select(s => new StorageByMachineViewModel + { + Id = s.Id, + Company = + s.OwnedMachine.Machine.Company + .Name, + Machine = + $"{s.OwnedMachine.Machine.Company.Name} {s.OwnedMachine.Machine.Name} <{s.OwnedMachine.User.UserName}>", + Type = s.Type, + Interface = s.Interface, + Capacity = s.Capacity + }).FirstOrDefaultAsync(m => m.Id == id); + if(storageByOwnedMachine == null) return NotFound(); + + return View(storageByOwnedMachine); + } + + // POST: Admin/StorageByOwnedMachines/Delete/5 + [HttpPost] + [ActionName("Delete")] + [ValidateAntiForgeryToken] + public async Task DeleteConfirmed(long id) + { + StorageByOwnedMachine storageByOwnedMachine = await _context.StorageByOwnedMachine.FindAsync(id); + _context.StorageByOwnedMachine.Remove(storageByOwnedMachine); + await _context.SaveChangesAsync(); + return RedirectToAction(nameof(Index)); + } + + bool StorageByOwnedMachineExists(long id) + { + return _context.StorageByOwnedMachine.Any(e => e.Id == id); + } + } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/Companies/Index.cshtml b/cicm_web/Areas/Admin/Views/Companies/Index.cshtml index c196be6d..67688165 100644 --- a/cicm_web/Areas/Admin/Views/Companies/Index.cshtml +++ b/cicm_web/Areas/Admin/Views/Companies/Index.cshtml @@ -29,7 +29,7 @@ // Copyright © 2003-2018 Natalia Portillo *******************************************************************************/ } -@using cicm_web.Areas.Admin.Models +@using CompanyViewModel = cicm_web.Areas.Admin.Models.CompanyViewModel @model IEnumerable @{ diff --git a/cicm_web/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml b/cicm_web/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml index 1b7eb70f..232d3b27 100644 --- a/cicm_web/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml +++ b/cicm_web/Areas/Admin/Views/InstructionSetExtensionsByProcessor/Delete.cshtml @@ -16,13 +16,13 @@
@Html.DisplayFor(model => model.Extension.Extension) -
+
@Html.DisplayNameFor(model => model.Processor)
@Html.DisplayFor(model => model.Processor.Name) -
+
diff --git a/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Create.cshtml b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Create.cshtml new file mode 100644 index 00000000..9da49f1a --- /dev/null +++ b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Create.cshtml @@ -0,0 +1,107 @@ +@{ + /****************************************************************************** +// 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.StorageByOwnedMachine + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

Storage by machine

+
+
+
+ +
+
+
+ + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+ + +
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Delete.cshtml b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Delete.cshtml new file mode 100644 index 00000000..7678555b --- /dev/null +++ b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Delete.cshtml @@ -0,0 +1,82 @@ +@{ + /****************************************************************************** +// 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_web.Areas.Admin.Models.StorageByMachineViewModel + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

Storage by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+ @Html.DisplayNameFor(model => model.Interface) +
+
+ @Html.DisplayFor(model => model.Interface) +
+
+ @Html.DisplayNameFor(model => model.Capacity) +
+
+ @Html.DisplayFor(model => model.Capacity) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+ +
+ + + + Back to List + +
+
\ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Details.cshtml b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Details.cshtml new file mode 100644 index 00000000..bc19156c --- /dev/null +++ b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Details.cshtml @@ -0,0 +1,80 @@ +@{ + /****************************************************************************** +// 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.StorageByMachineViewModel + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

Storage by machine

+
+
+
+ @Html.DisplayNameFor(model => model.Type) +
+
+ @Html.DisplayFor(model => model.Type) +
+
+ @Html.DisplayNameFor(model => model.Interface) +
+
+ @Html.DisplayFor(model => model.Interface) +
+
+ @Html.DisplayNameFor(model => model.Capacity) +
+
+ @Html.DisplayFor(model => model.Capacity) +
+
+ @Html.DisplayNameFor(model => model.Machine) +
+
+ @Html.DisplayFor(model => model.Machine) +
+
+
+ \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Edit.cshtml b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Edit.cshtml new file mode 100644 index 00000000..8e297216 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Edit.cshtml @@ -0,0 +1,112 @@ +@{ + /****************************************************************************** +// 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.StorageByOwnedMachine + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

Storage by machine

+
+
+
+
+
+
+
+ + + + +
+
+ + + + +
+
+ + + + +
+
+ + + + +
+ + +
+
+
+ +@section Scripts { + @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } +} \ No newline at end of file diff --git a/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Index.cshtml b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/Index.cshtml new file mode 100644 index 00000000..74c5b5a7 --- /dev/null +++ b/cicm_web/Areas/Admin/Views/StorageByOwnedMachines/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"] = "Storage by machines (Admin)"; +} + +

Storage by machines

+ +

+ + Create New + +

+ + + + + + + + + + + + + @foreach(StorageByMachineViewModel item in Model) + { + + + + + + + + + } + +
+ @Html.DisplayNameFor(model => model.Company) + + @Html.DisplayNameFor(model => model.Machine) + + @Html.DisplayNameFor(model => model.Type) + + @Html.DisplayNameFor(model => model.Interface) + + @Html.DisplayNameFor(model => model.Capacity) +
+ @Html.DisplayFor(modelItem => item.Company) + + @Html.DisplayFor(modelItem => item.Machine) + + @Html.DisplayFor(modelItem => item.Type) + + @Html.DisplayFor(modelItem => item.Interface) + + @Html.DisplayFor(modelItem => item.Capacity) + + + Details + + + Edit + + + Delete + +
\ No newline at end of file