diff --git a/Marechai/Areas/Admin/Controllers/MemoryByMachinesController.cs b/Marechai/Areas/Admin/Controllers/MemoryByMachinesController.cs deleted file mode 100644 index 5f45f916..00000000 --- a/Marechai/Areas/Admin/Controllers/MemoryByMachinesController.cs +++ /dev/null @@ -1,184 +0,0 @@ -/****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// Filename : MemoryByMachinesController.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-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 MemoryByMachinesController : Controller - { - readonly MarechaiContext _context; - - public MemoryByMachinesController(MarechaiContext context) => _context = context; - - // GET: Admin/MemoryByMachines - public async Task Index() - { - IIncludableQueryable marechaiContext = - _context.MemoryByMachine.Include(m => m.Machine); - - return View(await marechaiContext.OrderBy(m => m.Machine.Name).ThenBy(m => m.Usage).ThenBy(m => m.Size). - ThenBy(m => m.Type).Select(m => new MemoryByMachineViewModel - { - Id = m.Id, Machine = m.Machine.Name, Size = m.Size, Speed = m.Speed, - Type = m.Type, Usage = m.Usage - }).ToListAsync()); - } - - // GET: Admin/MemoryByMachines/Details/5 - public async Task Details(long? id) - { - if(id == null) - return NotFound(); - - MemoryByMachine memoryByMachine = - await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id); - - if(memoryByMachine == null) - return NotFound(); - - return View(memoryByMachine); - } - - // GET: Admin/MemoryByMachines/Create - public IActionResult Create() - { - ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name"); - - return View(); - } - - // POST: Admin/MemoryByMachines/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("MachineId,Type,Usage,Size,Speed,Id")] - MemoryByMachine memoryByMachine) - { - if(ModelState.IsValid) - { - _context.Add(memoryByMachine); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId); - - return View(memoryByMachine); - } - - // GET: Admin/MemoryByMachines/Edit/5 - public async Task Edit(long? id) - { - if(id == null) - return NotFound(); - - MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id); - - if(memoryByMachine == null) - return NotFound(); - - ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId); - - return View(memoryByMachine); - } - - // POST: Admin/MemoryByMachines/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("MachineId,Type,Usage,Size,Speed,Id")] - MemoryByMachine memoryByMachine) - { - if(id != memoryByMachine.Id) - return NotFound(); - - if(ModelState.IsValid) - { - try - { - _context.Update(memoryByMachine); - await _context.SaveChangesAsync(); - } - catch(DbUpdateConcurrencyException) - { - if(!MemoryByMachineExists(memoryByMachine.Id)) - return NotFound(); - - throw; - } - - return RedirectToAction(nameof(Index)); - } - - ViewData["MachineId"] = new SelectList(_context.Machines, "Id", "Name", memoryByMachine.MachineId); - - return View(memoryByMachine); - } - - // GET: Admin/MemoryByMachines/Delete/5 - public async Task Delete(long? id) - { - if(id == null) - return NotFound(); - - MemoryByMachine memoryByMachine = - await _context.MemoryByMachine.Include(m => m.Machine).FirstOrDefaultAsync(m => m.Id == id); - - if(memoryByMachine == null) - return NotFound(); - - return View(memoryByMachine); - } - - // POST: Admin/MemoryByMachines/Delete/5 - [HttpPost, ActionName("Delete"), ValidateAntiForgeryToken] - public async Task DeleteConfirmed(long id) - { - MemoryByMachine memoryByMachine = await _context.MemoryByMachine.FindAsync(id); - _context.MemoryByMachine.Remove(memoryByMachine); - await _context.SaveChangesAsync(); - - return RedirectToAction(nameof(Index)); - } - - bool MemoryByMachineExists(long id) => _context.MemoryByMachine.Any(e => e.Id == id); - } -} \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/MemoryByMachines/Create.cshtml b/Marechai/Areas/Admin/Views/MemoryByMachines/Create.cshtml deleted file mode 100644 index 17610230..00000000 --- a/Marechai/Areas/Admin/Views/MemoryByMachines/Create.cshtml +++ /dev/null @@ -1,94 +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 -*******************************************************************************/ -} -@using Marechai.Database -@model Marechai.Database.Models.MemoryByMachine - -@{ - ViewData["Title"] = "Create"; -} -

Create

-

Memory by machine

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

Delete

-

Are you sure you want to delete this?

-
-

Memory by machine

-
-
-
- @Html.DisplayNameFor(model => model.Machine) -
-
- @Html.DisplayFor(model => model.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/Marechai/Areas/Admin/Views/MemoryByMachines/Details.cshtml b/Marechai/Areas/Admin/Views/MemoryByMachines/Details.cshtml deleted file mode 100644 index d6dd8ca2..00000000 --- a/Marechai/Areas/Admin/Views/MemoryByMachines/Details.cshtml +++ /dev/null @@ -1,81 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// 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-2020 Natalia Portillo -*******************************************************************************/ -} -@model Marechai.Database.Models.MemoryByMachine - -@{ - ViewData["Title"] = "Details"; -} -

Details

-
-

Memory by machine

-
-
-
- @Html.DisplayNameFor(model => model.Machine) -
-
- @Html.DisplayFor(model => model.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) -
-
-
- \ No newline at end of file diff --git a/Marechai/Areas/Admin/Views/MemoryByMachines/Edit.cshtml b/Marechai/Areas/Admin/Views/MemoryByMachines/Edit.cshtml deleted file mode 100644 index ce9a383e..00000000 --- a/Marechai/Areas/Admin/Views/MemoryByMachines/Edit.cshtml +++ /dev/null @@ -1,95 +0,0 @@ -@{ - /****************************************************************************** -// MARECHAI: Master repository of computing history artifacts information -// ---------------------------------------------------------------------------- -// -// 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-2020 Natalia Portillo -*******************************************************************************/ -} -@using Marechai.Database -@model Marechai.Database.Models.MemoryByMachine - -@{ - ViewData["Title"] = "Edit"; -} -

Edit

-

Memory by machine

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

Memory by machines

-

- - Create new - -

- - - - - - - - - - - - - @foreach (var 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 diff --git a/Marechai/Marechai.csproj b/Marechai/Marechai.csproj index 9f434ed6..ff2f634a 100644 --- a/Marechai/Marechai.csproj +++ b/Marechai/Marechai.csproj @@ -2,7 +2,7 @@ netcoreapp3.1 - 3.0.99.1385 + 3.0.99.1387 Canary Islands Computer Museum Copyright © 2003-2020 Natalia Portillo Canary Islands Computer Museum Website @@ -159,5 +159,10 @@ <_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Details.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Edit.cshtml" /> <_ContentIncludedByDefault Remove="Areas\Admin\Views\ProcessorsByMachines\Index.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Create.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Delete.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Details.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Edit.cshtml" /> + <_ContentIncludedByDefault Remove="Areas\Admin\Views\MemoryByMachines\Index.cshtml" /> \ No newline at end of file diff --git a/Marechai/Pages/Admin/Details/Machine.razor b/Marechai/Pages/Admin/Details/Machine.razor index d3c248a6..3dfb7447 100644 --- a/Marechai/Pages/Admin/Details/Machine.razor +++ b/Marechai/Pages/Admin/Details/Machine.razor @@ -45,6 +45,7 @@ @inject SoundSynthsService SoundSynthsService @inject ProcessorsByMachineService ProcessorsByMachineService @inject ProcessorsService ProcessorsService +@inject MemoriesByMachineService MemoriesByMachineService @attribute [Authorize(Roles = "UberAdmin, Admin")]

@L["Machine details"]


@@ -345,6 +346,123 @@ } +
+

@L["Memory belonging to this machine"]

+ + @if (_addingMemory) + { +
+ + @L["Memory type"] + + + + @L["Memory usage"] + + + + @L["Nominal speed (MHz)"] + @L["Unknown (memory by machine speed)"] + @if (!_unknownMemorySpeed) + { + + + + @L["Please enter a valid speed for this memory."] + + + + } + + + @L["Memory size (bytes)"] + @L["Unknown (memory by machine size)"] + @if (!_unknownMemorySize) + { + + + + @L["Please enter a valid size for this memory."] + + + + } + + + +
+ } + @if (_machineMemories?.Count > 0) + { +
+ + + + + + + + + + + + @foreach (var item in _machineMemories) + { + + + + + + + + } + +
+ @L["Type"] + + @L["Usage"] + + @L["Size"] + + @L["Speed"] +
+ @item.Type + + @item.Usage + + @if (item.Size.HasValue) + { + @string.Format(L["{0} bytes"], item.Size) + } + else + { + @L["Unknown (memory by machine speed)"] + } + + @if (item.Speed.HasValue) + { + @string.Format(L["{0:F3} MHz"], item.Speed) + } + else + { + @L["Unknown (memory by machine speed)"] + } + + +
+
+ } + diff --git a/Marechai/Pages/Admin/Details/Machine.razor.cs b/Marechai/Pages/Admin/Details/Machine.razor.cs index 9bda4e55..3dcae168 100644 --- a/Marechai/Pages/Admin/Details/Machine.razor.cs +++ b/Marechai/Pages/Admin/Details/Machine.razor.cs @@ -12,10 +12,16 @@ namespace Marechai.Pages.Admin.Details { public partial class Machine { - bool _addingCpu; - int? _addingCpuId; - bool _addingGpu; - int? _addingGpuId; + bool _addingCpu; + int? _addingCpuId; + bool _addingGpu; + int? _addingGpuId; + bool _addingMemory; + long? _addingMemorySize; + double? _addingMemorySpeed; + + int _addingMemoryType; + int _addingMemoryUsage; float? _addingProcessorSpeed; bool _addingSound; int? _addingSoundId; @@ -24,12 +30,14 @@ namespace Marechai.Pages.Admin.Details bool _creating; ProcessorByMachineViewModel _currentCpuByMachine; GpuByMachineViewModel _currentGpuByMachine; + MemoryByMachineViewModel _currentMemoryByMachine; SoundSynthByMachineViewModel _currentSoundByMachine; bool _deleteInProgress; string _deleteText; string _deleteTitle; bool _deletingCpuByMachine; bool _deletingGpuByMachine; + bool _deletingMemoryByMachine; bool _deletingSoundByMachine; bool _editing; List _families; @@ -38,15 +46,19 @@ namespace Marechai.Pages.Admin.Details bool _loaded; List _machineCpus; List _machineGpus; + List _machineMemories; List _machineSound; MachineViewModel _model; bool _noFamily; bool _prototype; bool _savingCpu; bool _savingGpu; + bool _savingMemory; bool _savingSound; List _soundSynths; bool _unknownIntroduced; + bool _unknownMemorySize; + bool _unknownMemorySpeed; bool _unknownModel; bool _unknownProcessorSpeed; [Parameter] @@ -72,14 +84,15 @@ namespace Marechai.Pages.Admin.Details !_creating) return; - _companies = await CompaniesService.GetAsync(); - _families = await MachineFamiliesService.GetAsync(); - _model = _creating ? new MachineViewModel() : await Service.GetAsync(Id); - _machineGpus = await GpusByMachineService.GetByMachine(Id); - _machineCpus = await ProcessorsByMachineService.GetByMachine(Id); - _gpus = await GpusService.GetAsync(); - _cpus = await ProcessorsService.GetAsync(); - _soundSynths = await SoundSynthsService.GetAsync(); + _companies = await CompaniesService.GetAsync(); + _families = await MachineFamiliesService.GetAsync(); + _model = _creating ? new MachineViewModel() : await Service.GetAsync(Id); + _machineGpus = await GpusByMachineService.GetByMachine(Id); + _machineCpus = await ProcessorsByMachineService.GetByMachine(Id); + _gpus = await GpusService.GetAsync(); + _cpus = await ProcessorsService.GetAsync(); + _soundSynths = await SoundSynthsService.GetAsync(); + _machineMemories = await MemoriesByMachineService.GetByMachine(Id); _editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant(). StartsWith("admin/machines/edit/", @@ -220,7 +233,7 @@ namespace Marechai.Pages.Admin.Details _currentCpuByMachine = null; } - async Task OnAddGpuClick() + void OnAddGpuClick() { _addingGpu = true; _savingGpu = false; @@ -299,7 +312,7 @@ namespace Marechai.Pages.Admin.Details StateHasChanged(); } - async Task OnAddSoundClick() + void OnAddSoundClick() { _addingSound = true; _savingSound = false; @@ -383,7 +396,7 @@ namespace Marechai.Pages.Admin.Details StateHasChanged(); } - async Task OnAddCpuClick() + void OnAddCpuClick() { _addingCpu = true; _savingCpu = false; @@ -441,5 +454,107 @@ namespace Marechai.Pages.Admin.Details e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error; } + + void ShowMemoryDeleteModal(long itemId) + { + _currentMemoryByMachine = _machineMemories.FirstOrDefault(n => n.Id == itemId); + _deletingMemoryByMachine = true; + _deleteTitle = L["Delete memory from this machine"]; + + _deleteText = + string.Format(L["Are you sure you want to delete the memory type {0} with usage {1} from this machine?"], + _currentMemoryByMachine?.Type, _currentMemoryByMachine?.Usage); + + _frmDelete.Show(); + } + + async Task ConfirmDeleteMemoryByMachine() + { + if(_currentMemoryByMachine is null) + return; + + _deleteInProgress = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await MemoriesByMachineService.DeleteAsync(_currentMemoryByMachine.Id); + _machineMemories = await MemoriesByMachineService.GetByMachine(Id); + + _deleteInProgress = false; + _frmDelete.Hide(); + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void OnAddMemoryClick() + { + _addingMemory = true; + _savingMemory = false; + _addingMemorySpeed = 0; + _unknownMemorySpeed = true; + _addingMemorySize = 0; + _unknownMemorySize = true; + } + + void CancelAddMemory() + { + _addingMemory = false; + _savingMemory = false; + } + + async Task ConfirmAddMemory() + { + // TODO: Validation + + _savingMemory = true; + + // Yield thread to let UI to update + await Task.Yield(); + + await MemoriesByMachineService.CreateAsync(Id, (MemoryType)_addingMemoryType, + (MemoryUsage)_addingMemoryUsage, + _unknownMemorySize ? null : _addingMemorySize, + _unknownMemorySpeed ? null : _addingMemorySpeed); + + _machineMemories = await MemoriesByMachineService.GetByMachine(Id); + + _addingMemory = false; + _savingMemory = false; + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void ValidateMemorySpeed(ValidatorEventArgs e) + { + if(!(e.Value is double item)) + { + e.Status = ValidationStatus.Error; + + return; + } + + e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error; + } + + void ValidateMemorySize(ValidatorEventArgs e) + { + if(!(e.Value is long item)) + { + e.Status = ValidationStatus.Error; + + return; + } + + e.Status = item > 0 ? ValidationStatus.Success : ValidationStatus.Error; + } } } \ No newline at end of file diff --git a/Marechai/Services/MemoriesByMachineService.cs b/Marechai/Services/MemoriesByMachineService.cs new file mode 100644 index 00000000..df9e1eed --- /dev/null +++ b/Marechai/Services/MemoriesByMachineService.cs @@ -0,0 +1,51 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Marechai.Database; +using Marechai.Database.Models; +using Marechai.ViewModels; +using Microsoft.EntityFrameworkCore; + +namespace Marechai.Services +{ + public class MemoriesByMachineService + { + readonly MarechaiContext _context; + + public MemoriesByMachineService(MarechaiContext context) => _context = context; + + public async Task> GetByMachine(int machineId) => + await _context.MemoryByMachine.Where(m => m.MachineId == machineId).Select(m => new MemoryByMachineViewModel + { + Id = m.Id, Type = m.Type, Usage = m.Usage, Size = m.Size, + Speed = m.Speed, MachineId = m.MachineId + }).OrderBy(m => m.Type).ThenBy(m => m.Usage).ThenBy(m => m.Size).ThenBy(m => m.Speed).ToListAsync(); + + public async Task DeleteAsync(long id) + { + MemoryByMachine item = await _context.MemoryByMachine.FindAsync(id); + + if(item is null) + return; + + _context.MemoryByMachine.Remove(item); + + await _context.SaveChangesAsync(); + } + + public async Task CreateAsync(int machineId, MemoryType type, MemoryUsage usage, long? size, + double? speed) + { + var item = new MemoryByMachine + { + MachineId = machineId, Type = type, Usage = usage, Size = size, + Speed = speed + }; + + await _context.MemoryByMachine.AddAsync(item); + await _context.SaveChangesAsync(); + + return item.Id; + } + } +} \ No newline at end of file diff --git a/Marechai/Services/Register.cs b/Marechai/Services/Register.cs index 7ad76339..180bbefc 100644 --- a/Marechai/Services/Register.cs +++ b/Marechai/Services/Register.cs @@ -65,6 +65,7 @@ namespace Marechai.Services services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Marechai/ViewModels/MemoryByMachineViewModel.cs b/Marechai/ViewModels/MemoryByMachineViewModel.cs new file mode 100644 index 00000000..48f0b94f --- /dev/null +++ b/Marechai/ViewModels/MemoryByMachineViewModel.cs @@ -0,0 +1,13 @@ +using Marechai.Database; + +namespace Marechai.ViewModels +{ + public class MemoryByMachineViewModel : BaseViewModel + { + public int MachineId { get; set; } + public MemoryType Type { get; set; } + public MemoryUsage Usage { get; set; } + public long? Size { get; set; } + public double? Speed { get; set; } + } +} \ No newline at end of file