diff --git a/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsController.cs b/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsController.cs deleted file mode 100644 index 70d22fd8..00000000 --- a/Marechai/Areas/Admin/Controllers/InstructionSetExtensionsController.cs +++ /dev/null @@ -1,170 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : InstructionSetExtensionsController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Instruction set extensions 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-2020 Natalia Portillo -*******************************************************************************/ - -using System; -using System.Linq; -using System.Threading.Tasks; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace Marechai.Areas.Admin.Controllers -{ - [Area("Admin"), Authorize] - public class InstructionSetExtensionsController : Controller - { - readonly MarechaiContext _context; - - public InstructionSetExtensionsController(MarechaiContext context) => _context = context; - - // GET: Admin/InstructionSetExtensions - public async Task Index() => - View(await _context.InstructionSetExtensions.OrderBy(e => e.Extension).ToListAsync()); - - // GET: Admin/InstructionSetExtensions/Details/5 - public async Task Details(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtension instructionSetExtension = - await _context.InstructionSetExtensions.FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSetExtension == null) - return NotFound(); - - ViewBag.Processors = _context.InstructionSetExtensionsByProcessor.Where(e => e.ExtensionId == id). - Join(_context.Processors, p => p.ProcessorId, i => i.Id, (p, i) => i). - Select(p => p.Name); - - return View(instructionSetExtension); - } - - // GET: Admin/InstructionSetExtensions/Create - public IActionResult Create() => View(); - - // POST: Admin/InstructionSetExtensions/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("Id,Extension")] InstructionSetExtension instructionSetExtension) - { - if(ModelState.IsValid) - { - _context.Add(instructionSetExtension); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - return View(instructionSetExtension); - } - - // GET: Admin/InstructionSetExtensions/Edit/5 - public async Task Edit(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtension instructionSetExtension = await _context.InstructionSetExtensions.FindAsync(id); - - if(instructionSetExtension == null) - return NotFound(); - - return View(instructionSetExtension); - } - - // POST: Admin/InstructionSetExtensions/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("Id,Extension")] InstructionSetExtension instructionSetExtension) - { - if(id != instructionSetExtension.Id) - return NotFound(); - - if(ModelState.IsValid) - { - try - { - _context.Update(instructionSetExtension); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - if(!InstructionSetExtensionExists(instructionSetExtension.Id)) - return NotFound(); - - throw; - } - - return RedirectToAction(nameof(Index)); - } - - return View(instructionSetExtension); - } - - // GET: Admin/InstructionSetExtensions/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - return NotFound(); - - InstructionSetExtension instructionSetExtension = - await _context.InstructionSetExtensions.FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSetExtension == null) - return NotFound(); - - return View(instructionSetExtension); - } - - // POST: Admin/InstructionSetExtensions/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - InstructionSetExtension instructionSetExtension = await _context.InstructionSetExtensions.FindAsync(id); - _context.InstructionSetExtensions.Remove(instructionSetExtension); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - bool InstructionSetExtensionExists(int id) => _context.InstructionSetExtensions.Any(e => e.Id == id); - - [AcceptVerbs("Get", "Post")] - public IActionResult VerifyUnique(string extension) => - _context.InstructionSetExtensions.Any(i => string.Equals(i.Extension, extension, - StringComparison.InvariantCultureIgnoreCase)) - ? Json("Instruction set extension already exists.") : Json(true); - } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Controllers/InstructionSetsController.cs b/Marechai/Areas/Admin/Controllers/InstructionSetsController.cs deleted file mode 100644 index fefec9ce..00000000 --- a/Marechai/Areas/Admin/Controllers/InstructionSetsController.cs +++ /dev/null @@ -1,160 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : InstructionSetsController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Instruction sets 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-2020 Natalia Portillo -*******************************************************************************/ - -using System; -using System.Linq; -using System.Threading.Tasks; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; - -namespace Marechai.Areas.Admin.Controllers -{ - [Area("Admin"), Authorize] - public class InstructionSetsController : Controller - { - readonly MarechaiContext _context; - - public InstructionSetsController(MarechaiContext context) => _context = context; - - // GET: Admin/InstructionSets - public async Task Index() => - View(await _context.InstructionSets.OrderBy(s => s.Name).ToListAsync()); - - // GET: Admin/InstructionSets/Details/5 - public async Task Details(int? id) - { - if(id == null) - return NotFound(); - - InstructionSet instructionSet = await _context.InstructionSets.FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSet == null) - return NotFound(); - - return View(instructionSet); - } - - // GET: Admin/InstructionSets/Create - public IActionResult Create() => View(); - - // POST: Admin/InstructionSets/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("Id,Name")] InstructionSet instructionSet) - { - if(!ModelState.IsValid) - return View(instructionSet); - - _context.Add(instructionSet); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - // GET: Admin/InstructionSets/Edit/5 - public async Task Edit(int? id) - { - if(id == null) - return NotFound(); - - InstructionSet instructionSet = await _context.InstructionSets.FindAsync(id); - - if(instructionSet == null) - return NotFound(); - - return View(instructionSet); - } - - // POST: Admin/InstructionSets/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("Id,Name")] InstructionSet instructionSet) - { - if(id != instructionSet.Id) - return NotFound(); - - if(ModelState.IsValid) - { - try - { - _context.Update(instructionSet); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - if(!InstructionSetExists(instructionSet.Id)) - return NotFound(); - - throw; - } - - return RedirectToAction(nameof(Index)); - } - - return View(instructionSet); - } - - // GET: Admin/InstructionSets/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - return NotFound(); - - InstructionSet instructionSet = await _context.InstructionSets.FirstOrDefaultAsync(m => m.Id == id); - - if(instructionSet == null) - return NotFound(); - - return View(instructionSet); - } - - // POST: Admin/InstructionSets/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - InstructionSet instructionSet = await _context.InstructionSets.FindAsync(id); - _context.InstructionSets.Remove(instructionSet); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - bool InstructionSetExists(int id) => _context.InstructionSets.Any(e => e.Id == id); - - [AcceptVerbs("Get", "Post")] - public IActionResult VerifyUnique(string name) => - _context.InstructionSets.Any(i => string.Equals(i.Name, name, StringComparison.InvariantCultureIgnoreCase)) - ? Json("Instruction set already exists.") : Json(true); - } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensions/Create.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensions/Create.cshtml deleted file mode 100644 index c3fcec5f..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensions/Create.cshtml +++ /dev/null @@ -1,64 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// 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-2020 Natalia Portillo -*******************************************************************************/ -} -@model Marechai.Database.Models.InstructionSetExtension - -@{ - ViewData["Title"] = "Create"; -} -

Create

-

Instruction set extension

-
-
-
-
-
-
-
- - - - -
- -
-
-
- -@section Scripts { - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/InstructionSets/Create.cshtml b/Marechai/Areas/Admin/Views/InstructionSets/Create.cshtml deleted file mode 100644 index 14bee765..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSets/Create.cshtml +++ /dev/null @@ -1,64 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// 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-2020 Natalia Portillo -*******************************************************************************/ -} -@model Marechai.Database.Models.InstructionSet - -@{ - ViewData["Title"] = "Create"; -} -

Create

-

Instruction set

-
-
-
-
-
-
-
- - - - -
- -
-
-
- -@section Scripts { - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } -} \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index d2ec2bb9..9463c1ba 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1245 + 3.0.99.1246 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -132,5 +132,7 @@ <_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentCompanies\Create.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\DocumentPeople\Create.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\Gpus\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSetExtensions\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\InstructionSets\Create.cshtml" /> \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/InstructionSet.razor b/Marechai/Pages/Admin/Details/InstructionSet.razor index fc52345e..f46104a4 100644 --- a/Marechai/Pages/Admin/Details/InstructionSet.razor +++ b/Marechai/Pages/Admin/Details/InstructionSet.razor @@ -32,6 +32,7 @@ @page "/admin/instruction_sets/details/{Id:int}" @page "/admin/instruction_sets/edit/{Id:int}" +@page "/admin/instruction_sets/create" @inherits OwningComponentBase @inject IStringLocalizer L @attribute [Authorize(Roles = "UberAdmin, Admin")] diff --git a/Marechai/Pages/Admin/Details/InstructionSet.razor.cs b/Marechai/Pages/Admin/Details/InstructionSet.razor.cs index d9d1d9a6..7139e70b 100644 --- a/Marechai/Pages/Admin/Details/InstructionSet.razor.cs +++ b/Marechai/Pages/Admin/Details/InstructionSet.razor.cs @@ -8,8 +8,9 @@ namespace Marechai.Pages.Admin.Details { public partial class InstructionSet { - bool _editing; - bool _loaded; + bool _creating; + bool _editing; + bool _loaded; Database.Models.InstructionSet _model; [Parameter] public int Id { get; set; } @@ -21,14 +22,19 @@ namespace Marechai.Pages.Admin.Details _loaded = true; - if(Id <= 0) + _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/instruction_sets/create", + StringComparison.InvariantCulture); + + if(Id <= 0 && + !_creating) return; - _model = await Service.GetAsync(Id); + _model = _creating ? new Database.Models.InstructionSet() : await Service.GetAsync(Id); - _editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). - StartsWith("admin/instruction_sets/edit/", - StringComparison.InvariantCulture); + _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/instruction_sets/edit/", + StringComparison.InvariantCulture); StateHasChanged(); } @@ -42,7 +48,15 @@ namespace Marechai.Pages.Admin.Details async void OnCancelClicked() { _editing = false; - _model = await Service.GetAsync(Id); + + if(_creating) + { + NavigationManager.ToBaseRelativePath("admin/instruction_sets"); + + return; + } + + _model = await Service.GetAsync(Id); StateHasChanged(); } @@ -53,9 +67,14 @@ namespace Marechai.Pages.Admin.Details !Service.VerifyUnique(_model.Name)) return; - _editing = false; - await Service.UpdateAsync(_model); - _model = await Service.GetAsync(Id); + if(_creating) + Id = await Service.CreateAsync(_model); + else + await Service.UpdateAsync(_model); + + _editing = false; + _creating = false; + _model = await Service.GetAsync(Id); StateHasChanged(); } diff --git a/Marechai/Pages/Admin/InstructionSets.razor b/Marechai/Pages/Admin/InstructionSets.razor index 382f9583..f0fda307 100644 --- a/Marechai/Pages/Admin/InstructionSets.razor +++ b/Marechai/Pages/Admin/InstructionSets.razor @@ -42,9 +42,7 @@ return; }

- - @L["Create new"] - + @L["Create new"]

diff --git a/Marechai/Services/InstructionSetsService.cs b/Marechai/Services/InstructionSetsService.cs index eef02694..42ff3749 100644 --- a/Marechai/Services/InstructionSetsService.cs +++ b/Marechai/Services/InstructionSetsService.cs @@ -37,6 +37,19 @@ namespace Marechai.Services await _context.SaveChangesAsync(); } + public async Task CreateAsync(InstructionSet viewModel) + { + var model = new InstructionSet + { + Name = viewModel.Name + }; + + await _context.InstructionSets.AddAsync(model); + await _context.SaveChangesAsync(); + + return model.Id; + } + public async Task DeleteAsync(int id) { InstructionSet item = await _context.InstructionSets.FindAsync(id);