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

Delete

-

Are you sure you want to delete this?

-
-

GPU

-
-
-
- @Html.DisplayNameFor(model => model.Company) -
-
- @Html.DisplayFor(model => model.Company.Name) -
-
- @Html.DisplayNameFor(model => model.Name) -
-
- @Html.DisplayFor(model => model.Name) -
-
- @Html.DisplayNameFor(model => model.ModelCode) -
-
- @Html.DisplayFor(model => model.ModelCode) -
-
- @Html.DisplayNameFor(model => model.Introduced) -
-
- @Html.DisplayFor(model => model.IntroducedView) -
-
- @Html.DisplayNameFor(model => model.Package) -
-
- @Html.DisplayFor(model => model.Package) -
-
- @Html.DisplayNameFor(model => model.Process) -
-
- @Html.DisplayFor(model => model.Process) -
-
- @Html.DisplayNameFor(model => model.ProcessNm) -
-
- @Html.DisplayFor(model => model.ProcessNm) -
-
- @Html.DisplayNameFor(model => model.DieSize) -
-
- @Html.DisplayFor(model => model.DieSize) -
-
- @Html.DisplayNameFor(model => model.Transistors) -
-
- @Html.DisplayFor(model => model.Transistors) -
-
-
- - - - Back to List - -
-
\ No newline at end of file diff --git a/Marechai/Pages/Admin/Gpus.razor b/Marechai/Pages/Admin/Gpus.razor index 422e6388..789b4bb1 100644 --- a/Marechai/Pages/Admin/Gpus.razor +++ b/Marechai/Pages/Admin/Gpus.razor @@ -87,21 +87,26 @@ @L["Edit"] - - @L["Delete"] - + } -@code -{ - List _gpus; - - protected override async Task OnInitializedAsync() - { - _gpus = await Service.GetAsync(); - } -} \ No newline at end of file + + + + + @L["Delete GPU"] + + + + @string.Format(@L["Are you sure you want to delete {0} {1}?"], _gpu?.Company, _gpu?.Name) + + + + + + + diff --git a/Marechai/Pages/Admin/Gpus.razor.cs b/Marechai/Pages/Admin/Gpus.razor.cs new file mode 100644 index 00000000..47fdeee8 --- /dev/null +++ b/Marechai/Pages/Admin/Gpus.razor.cs @@ -0,0 +1,52 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Blazorise; +using Marechai.ViewModels; + +namespace Marechai.Pages.Admin +{ + public partial class Gpus + { + bool _deleteInProgress; + Modal _frmDelete; + GpuViewModel _gpu; + List _gpus; + + void ShowModal(int itemId) + { + _gpu = _gpus.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_gpu is null) + return; + + _deleteInProgress = true; + _gpus = null; + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_gpu.Id); + _gpus = 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) => _gpu = null; + + protected override async Task OnInitializedAsync() => _gpus = await Service.GetAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/GpusService.es.resx b/Marechai/Resources/Services/GpusService.es.resx index b1e3fa00..136346bc 100644 --- a/Marechai/Resources/Services/GpusService.es.resx +++ b/Marechai/Resources/Services/GpusService.es.resx @@ -158,4 +158,16 @@ Eliminar Delete + + Eliminar gráfica + Delete GPU, abbreviated + + + ¿Está seguro de que desea borrar la gráfica {0}? + {0} company name, {1} gpu name + + + Cancelar + Cancel + \ No newline at end of file diff --git a/Marechai/Services/GpusService.cs b/Marechai/Services/GpusService.cs index e6664a9c..3c154efb 100644 --- a/Marechai/Services/GpusService.cs +++ b/Marechai/Services/GpusService.cs @@ -30,5 +30,17 @@ namespace Marechai.Services Process = g.Process, ProcessNm = g.ProcessNm, DieSize = g.DieSize, Transistors = g.Transistors }).ToListAsync(); + + public async Task DeleteAsync(int id) + { + Gpu item = await _context.Gpus.FindAsync(id); + + if(item is null) + return; + + _context.Gpus.Remove(item); + + await _context.SaveChangesAsync(); + } } } \ No newline at end of file