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

Delete

-

Are you sure you want to delete this?

-
-

Machine

-
-
-
- @Html.DisplayNameFor(model => model.Company) -
-
- @Html.DisplayFor(model => model.Company.Name) -
-
- @Html.DisplayNameFor(model => model.Family) -
-
- @Html.DisplayFor(model => model.Family.Name) -
-
- @Html.DisplayNameFor(model => model.Name) -
-
- @Html.DisplayFor(model => model.Name) -
-
- @Html.DisplayNameFor(model => model.Model) -
-
- @Html.DisplayFor(model => model.Model) -
-
- @Html.DisplayNameFor(model => model.Introduced) -
-
- @Html.DisplayFor(model => model.Introduced) -
-
- @Html.DisplayNameFor(model => model.Type) -
-
- @Html.DisplayFor(model => model.Type) -
-
-
- - - - Back to List - -
-
\ No newline at end of file diff --git a/Marechai/Pages/Admin/Machines.razor b/Marechai/Pages/Admin/Machines.razor index 8e030369..d579fb0b 100644 --- a/Marechai/Pages/Admin/Machines.razor +++ b/Marechai/Pages/Admin/Machines.razor @@ -99,21 +99,26 @@ @L["Edit"] - - @L["Delete"] - + } -@code -{ - List _machines; - - protected override async Task OnInitializedAsync() - { - _machines = await Service.GetAsync(); - } -} \ No newline at end of file + + + + + @L["Delete machine"] + + + + @string.Format(@L["Are you sure you want to delete {0} {1}?"], _machine?.Company, _machine?.Name) + + + + + + + diff --git a/Marechai/Pages/Admin/Machines.razor.cs b/Marechai/Pages/Admin/Machines.razor.cs new file mode 100644 index 00000000..11ec5935 --- /dev/null +++ b/Marechai/Pages/Admin/Machines.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 Machines + { + bool _deleteInProgress; + Modal _frmDelete; + MachineViewModel _machine; + List _machines; + + void ShowModal(int itemId) + { + _machine = _machines.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_machine is null) + return; + + _deleteInProgress = true; + _machines = null; + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_machine.Id); + _machines = 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) => _machine = null; + + protected override async Task OnInitializedAsync() => _machines = await Service.GetAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/MachinesService.es.resx b/Marechai/Resources/Services/MachinesService.es.resx index ead4bf35..4a055204 100644 --- a/Marechai/Resources/Services/MachinesService.es.resx +++ b/Marechai/Resources/Services/MachinesService.es.resx @@ -446,4 +446,16 @@ Compañía Company + + Eliminar máquina + Delete machine + + + ¿Está seguro de que desea borrar {0} {1}? + {0} company name, {1} machine name + + + Cancelar + Cancel + \ No newline at end of file diff --git a/Marechai/Services/MachinesService.cs b/Marechai/Services/MachinesService.cs index f7969ff4..52942f5f 100644 --- a/Marechai/Services/MachinesService.cs +++ b/Marechai/Services/MachinesService.cs @@ -93,5 +93,17 @@ namespace Marechai.Services return model; } + + public async Task DeleteAsync(int id) + { + Machine item = await _context.Machines.FindAsync(id); + + if(item is null) + return; + + _context.Machines.Remove(item); + + await _context.SaveChangesAsync(); + } } } \ No newline at end of file