diff --git a/Marechai/Areas/Admin/Views/InstructionSetExtensions/Delete.cshtml b/Marechai/Areas/Admin/Views/InstructionSetExtensions/Delete.cshtml deleted file mode 100644 index ee2ef16c..00000000 --- a/Marechai/Areas/Admin/Views/InstructionSetExtensions/Delete.cshtml +++ /dev/null @@ -1,57 +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.InstructionSetExtension - -@{ - ViewData["Title"] = "Delete"; -} -

Delete

-

Are you sure you want to delete this?

-
-

Instruction set extension

-
-
-
- @Html.DisplayNameFor(model => model.Extension) -
-
- @Html.DisplayFor(model => model.Extension) -
-
-
- - - - Back to List - -
-
\ No newline at end of file diff --git a/Marechai/Pages/Admin/InstructionSetExtensions.razor b/Marechai/Pages/Admin/InstructionSetExtensions.razor index dd6f4386..714a26a3 100644 --- a/Marechai/Pages/Admin/InstructionSetExtensions.razor +++ b/Marechai/Pages/Admin/InstructionSetExtensions.razor @@ -31,7 +31,6 @@ } @page "/admin/instruction_set_extensions" -@using Marechai.Database.Models @inherits OwningComponentBase @inject IStringLocalizer L @attribute [Authorize(Roles = "UberAdmin, Admin")] @@ -70,21 +69,26 @@ @L["Edit"] - - @L["Delete"] - + } -@code -{ - List _extensions; - - protected override async Task OnInitializedAsync() - { - _extensions = await Service.GetAsync(); - } -} \ No newline at end of file + + + + + @L["Delete extension"] + + + + @string.Format(@L["Are you sure you want to delete {0}?"], _extension?.Extension) + + + + + + + diff --git a/Marechai/Pages/Admin/InstructionSetExtensions.razor.cs b/Marechai/Pages/Admin/InstructionSetExtensions.razor.cs new file mode 100644 index 00000000..f53a9c6d --- /dev/null +++ b/Marechai/Pages/Admin/InstructionSetExtensions.razor.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Blazorise; +using Marechai.Database.Models; + +namespace Marechai.Pages.Admin +{ + public partial class InstructionSetExtensions + { + bool _deleteInProgress; + InstructionSetExtension _extension; + List _extensions; + Modal _frmDelete; + + void ShowModal(int itemId) + { + _extension = _extensions.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_extension is null) + return; + + _deleteInProgress = true; + _extensions = null; + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_extension.Id); + _extensions = await Service.GetAsync(); + + _deleteInProgress = false; + _frmDelete.Hide(); + + // Yield thread to let UI to update + await Task.Yield(); + + // Tell we finished loading + StateHasChanged(); + } + + void ModalClosing(ModalClosingEventArgs obj) => _extension = null; + + protected override async Task OnInitializedAsync() => _extensions = await Service.GetAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/InstructionSetExtensionsService.es.resx b/Marechai/Resources/Services/InstructionSetExtensionsService.es.resx index 613927b0..e2cdf818 100644 --- a/Marechai/Resources/Services/InstructionSetExtensionsService.es.resx +++ b/Marechai/Resources/Services/InstructionSetExtensionsService.es.resx @@ -146,4 +146,16 @@ Eliminar Delete + + Eliminar extensión + Delete extension + + + ¿Está seguro de que desea borrar {0}? + {0} instruction set extension name + + + Cancelar + Cancel + \ No newline at end of file diff --git a/Marechai/Services/InstructionSetExtensionsService.cs b/Marechai/Services/InstructionSetExtensionsService.cs index 76402de6..2287919b 100644 --- a/Marechai/Services/InstructionSetExtensionsService.cs +++ b/Marechai/Services/InstructionSetExtensionsService.cs @@ -14,5 +14,17 @@ namespace Marechai.Services public async Task> GetAsync() => await _context.InstructionSetExtensions.OrderBy(e => e.Extension).ToListAsync(); + + public async Task DeleteAsync(int id) + { + InstructionSetExtension item = await _context.InstructionSetExtensions.FindAsync(id); + + if(item is null) + return; + + _context.InstructionSetExtensions.Remove(item); + + await _context.SaveChangesAsync(); + } } } \ No newline at end of file