diff --git a/Marechai/Areas/Admin/Controllers/ProcessorsController.cs b/Marechai/Areas/Admin/Controllers/ProcessorsController.cs deleted file mode 100644 index 3dd5cc10..00000000 --- a/Marechai/Areas/Admin/Controllers/ProcessorsController.cs +++ /dev/null @@ -1,198 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : ProcessorsController.cs -// Author(s) : Natalia Portillo -// -// --[ Description ] ---------------------------------------------------------- -// -// Processors 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.Linq; -using System.Threading.Tasks; -using Marechai.Areas.Admin.Models; -using Marechai.Database.Models; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Query; - -namespace Marechai.Areas.Admin.Controllers -{ - [Area("Admin"), Authorize] - public class ProcessorsController : Controller - { - readonly MarechaiContext _context; - - public ProcessorsController(MarechaiContext context) => _context = context; - - // GET: Admin/Processors - public async Task Index() - { - IIncludableQueryable marechaiContext = - _context.Processors.Include(p => p.Company).Include(p => p.InstructionSet); - - return View(await marechaiContext.OrderBy(p => p.Company.Name).ThenBy(p => p.Name). - Select(p => new ProcessorViewModel - { - Company = p.Company.Name, Id = p.Id, - InstructionSet = p.InstructionSet.Name, Introduced = p.Introduced, - ModelCode = p.ModelCode, Name = p.Name - }).ToListAsync()); - } - - // GET: Admin/Processors/Details/5 - public async Task Details(int? id) - { - if(id == null) - return NotFound(); - - Processor processor = await _context.Processors.Include(p => p.Company).Include(p => p.InstructionSet). - FirstOrDefaultAsync(m => m.Id == id); - - if(processor == null) - return NotFound(); - - return View(processor); - } - - // GET: Admin/Processors/Create - public IActionResult Create() - { - ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name"); - ViewData["InstructionSetId"] = new SelectList(_context.InstructionSets, "Id", "Name"); - - return View(); - } - - // POST: Admin/Processors/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,CompanyId,ModelCode,Introduced,InstructionSetId,Speed,Package,Gprs,GprSize,Fprs,FprSize,Cores,ThreadsPerCore,Process,ProcessNm,DieSize,Transistors,DataBus,AddrBus,SimdRegisters,SimdSize,L1Instruction,L1Data,L2,L3")] - Processor processor) - { - if(ModelState.IsValid) - { - _context.Add(processor); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId); - - ViewData["InstructionSetId"] = - new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId); - - return View(processor); - } - - // GET: Admin/Processors/Edit/5 - public async Task Edit(int? id) - { - if(id == null) - return NotFound(); - - Processor processor = await _context.Processors.FindAsync(id); - - if(processor == null) - return NotFound(); - - ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId); - - ViewData["InstructionSetId"] = - new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId); - - return View(processor); - } - - // POST: Admin/Processors/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,CompanyId,ModelCode,Introduced,InstructionSetId,Speed,Package,Gprs,GprSize,Fprs,FprSize,Cores,ThreadsPerCore,Process,ProcessNm,DieSize,Transistors,DataBus,AddrBus,SimdRegisters,SimdSize,L1Instruction,L1Data,L2,L3")] - Processor processor) - { - if(id != processor.Id) - return NotFound(); - - if(ModelState.IsValid) - { - try - { - _context.Update(processor); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - if(!ProcessorExists(processor.Id)) - return NotFound(); - - throw; - } - - return RedirectToAction(nameof(Index)); - } - - ViewData["CompanyId"] = new SelectList(_context.Companies, "Id", "Name", processor.CompanyId); - - ViewData["InstructionSetId"] = - new SelectList(_context.InstructionSets, "Id", "Name", processor.InstructionSetId); - - return View(processor); - } - - // GET: Admin/Processors/Delete/5 - public async Task Delete(int? id) - { - if(id == null) - return NotFound(); - - Processor processor = await _context.Processors.Include(p => p.Company).Include(p => p.InstructionSet). - FirstOrDefaultAsync(m => m.Id == id); - - if(processor == null) - return NotFound(); - - return View(processor); - } - - // POST: Admin/Processors/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(int id) - { - Processor processor = await _context.Processors.FindAsync(id); - _context.Processors.Remove(processor); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - bool ProcessorExists(int id) => _context.Processors.Any(e => e.Id == id); - } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/Processors/Create.cshtml b/Marechai/Areas/Admin/Views/Processors/Create.cshtml deleted file mode 100644 index ac078df9..00000000 --- a/Marechai/Areas/Admin/Views/Processors/Create.cshtml +++ /dev/null @@ -1,230 +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.Processor - -@{ - ViewData["Title"] = "Create"; -} -

Create

-

Processor

-
-
-
-
-
-
-
- - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
-
- - - - -
- -
-
-
- -@section Scripts { - @{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); } -} \ No newline at end of file diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index b570d27f..56e2814f 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -139,5 +139,6 @@ <_ContentIncludedByDefault Remove="Areas\Admin\Views\MachineFamilies\Create.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\Machines\Create.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\People\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\Processors\Create.cshtml" /> \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/Processor.razor b/Marechai/Pages/Admin/Details/Processor.razor index 0c4cb09d..79b50410 100644 --- a/Marechai/Pages/Admin/Details/Processor.razor +++ b/Marechai/Pages/Admin/Details/Processor.razor @@ -32,6 +32,7 @@ @page "/admin/processors/details/{Id:int}" @page "/admin/processors/edit/{Id:int}" +@page "/admin/processors/create" @inherits OwningComponentBase @inject IStringLocalizer L @inject CompaniesService CompaniesService diff --git a/Marechai/Pages/Admin/Details/Processor.razor.cs b/Marechai/Pages/Admin/Details/Processor.razor.cs index d6f95063..fede4d83 100644 --- a/Marechai/Pages/Admin/Details/Processor.razor.cs +++ b/Marechai/Pages/Admin/Details/Processor.razor.cs @@ -11,6 +11,7 @@ namespace Marechai.Pages.Admin.Details public partial class Processor { List _companies; + bool _creating; bool _editing; List _instructionSets; bool _loaded; @@ -50,15 +51,20 @@ namespace Marechai.Pages.Admin.Details _loaded = true; - if(Id <= 0) + _creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/processors/create", StringComparison.InvariantCulture); + + if(Id <= 0 && + !_creating) return; _companies = await CompaniesService.GetAsync(); _instructionSets = await InstructionSetsService.GetAsync(); - _model = await Service.GetAsync(Id); + _model = _creating ? new ProcessorViewModel() : await Service.GetAsync(Id); - _editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). - StartsWith("admin/processors/edit/", StringComparison.InvariantCulture); + _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). + StartsWith("admin/processors/edit/", + StringComparison.InvariantCulture); if(_editing) SetCheckboxes(); @@ -105,7 +111,15 @@ namespace Marechai.Pages.Admin.Details async void OnCancelClicked() { _editing = false; - _model = await Service.GetAsync(Id); + + if(_creating) + { + NavigationManager.ToBaseRelativePath("admin/processors"); + + return; + } + + _model = await Service.GetAsync(Id); SetCheckboxes(); StateHasChanged(); } @@ -234,9 +248,14 @@ namespace Marechai.Pages.Admin.Details else if(_model.L3 < 0) 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); SetCheckboxes(); StateHasChanged(); } diff --git a/Marechai/Pages/Admin/Processors.razor b/Marechai/Pages/Admin/Processors.razor index 5f008791..e7aae0aa 100644 --- a/Marechai/Pages/Admin/Processors.razor +++ b/Marechai/Pages/Admin/Processors.razor @@ -42,9 +42,7 @@ return; }

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

diff --git a/Marechai/Services/ProcessorsService.cs b/Marechai/Services/ProcessorsService.cs index 0157ce78..36acd4e1 100644 --- a/Marechai/Services/ProcessorsService.cs +++ b/Marechai/Services/ProcessorsService.cs @@ -90,6 +90,27 @@ namespace Marechai.Services await _context.SaveChangesAsync(); } + public async Task CreateAsync(ProcessorViewModel viewModel) + { + var model = new Processor + { + AddrBus = viewModel.AddrBus, CompanyId = viewModel.CompanyId, Cores = viewModel.Cores, + DataBus = viewModel.DataBus, DieSize = viewModel.DieSize, Fprs = viewModel.Fprs, + FprSize = viewModel.FprSize, Gprs = viewModel.Gprs, GprSize = viewModel.GprSize, + InstructionSetId = viewModel.InstructionSetId, Introduced = viewModel.Introduced, + L1Data = viewModel.L1Data, L1Instruction = viewModel.L1Instruction, L2 = viewModel.L2, + L3 = viewModel.L3, ModelCode = viewModel.ModelCode, Name = viewModel.Name, Package = viewModel.Package, + Process = viewModel.Process, ProcessNm = viewModel.ProcessNm, SimdRegisters = viewModel.SimdRegisters, + SimdSize = viewModel.SimdSize, Speed = viewModel.Speed, ThreadsPerCore = viewModel.ThreadsPerCore, + Transistors = viewModel.Transistors + }; + + await _context.Processors.AddAsync(model); + await _context.SaveChangesAsync(); + + return model.Id; + } + public async Task DeleteAsync(int id) { Processor item = await _context.Processors.FindAsync(id);