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

Delete

-

Are you sure you want to delete this?

-
-

Machine family

-
-
-
- @Html.DisplayNameFor(model => model.Company) -
-
- @Html.DisplayFor(model => model.Company.Name) -
-
- @Html.DisplayNameFor(model => model.Name) -
-
- @Html.DisplayFor(model => model.Name) -
-
-
- - - - Back to List - -
-
\ No newline at end of file diff --git a/Marechai/Pages/Admin/MachineFamilies.razor b/Marechai/Pages/Admin/MachineFamilies.razor index b385ecad..113c297e 100644 --- a/Marechai/Pages/Admin/MachineFamilies.razor +++ b/Marechai/Pages/Admin/MachineFamilies.razor @@ -31,7 +31,6 @@ } @page "/admin/machine_families" -@using Marechai.Database.Models @inherits OwningComponentBase @inject IStringLocalizer L @attribute [Authorize(Roles = "UberAdmin, Admin")] @@ -76,21 +75,26 @@ @L["Edit"] - - @L["Delete"] - + } -@code -{ - List _machineFamilies; - - protected override async Task OnInitializedAsync() - { - _machineFamilies = await Service.GetAsync(); - } -} \ No newline at end of file + + + + + @L["Delete machine family"] + + + + @string.Format(@L["Are you sure you want to delete {0} {1}?"], _machineFamily?.Company, _machineFamily?.Name) + + + + + + + diff --git a/Marechai/Pages/Admin/MachineFamilies.razor.cs b/Marechai/Pages/Admin/MachineFamilies.razor.cs new file mode 100644 index 00000000..441b2844 --- /dev/null +++ b/Marechai/Pages/Admin/MachineFamilies.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 MachineFamilies + { + bool _deleteInProgress; + Modal _frmDelete; + List _machineFamilies; + MachineFamilyViewModel _machineFamily; + + void ShowModal(int itemId) + { + _machineFamily = _machineFamilies.FirstOrDefault(n => n.Id == itemId); + _frmDelete.Show(); + } + + void HideModal() => _frmDelete.Hide(); + + async void ConfirmDelete() + { + if(_machineFamily is null) + return; + + _deleteInProgress = true; + _machineFamilies = null; + + // Yield thread to let UI to update + await Task.Yield(); + + await Service.DeleteAsync(_machineFamily.Id); + _machineFamilies = 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) => _machineFamily = null; + + protected override async Task OnInitializedAsync() => _machineFamilies = await Service.GetAsync(); + } +} \ No newline at end of file diff --git a/Marechai/Resources/Services/MachineFamiliesService.es.resx b/Marechai/Resources/Services/MachineFamiliesService.es.resx index 9f9ede77..a78857ee 100644 --- a/Marechai/Resources/Services/MachineFamiliesService.es.resx +++ b/Marechai/Resources/Services/MachineFamiliesService.es.resx @@ -150,4 +150,16 @@ Eliminar Delete + + Eliminar familia de máquinas + Delete machine family + + + ¿Está seguro de que desea borrar {0} {1}? + {0} company name, {1} family name + + + Cancelar + Cancel + \ No newline at end of file diff --git a/Marechai/Services/MachineFamiliesService.cs b/Marechai/Services/MachineFamiliesService.cs index 645275a4..02e48f95 100644 --- a/Marechai/Services/MachineFamiliesService.cs +++ b/Marechai/Services/MachineFamiliesService.cs @@ -19,5 +19,17 @@ namespace Marechai.Services { Id = m.Id, Company = m.Company.Name, Name = m.Name }).ToListAsync(); + + public async Task DeleteAsync(int id) + { + MachineFamily item = await _context.MachineFamilies.FindAsync(id); + + if(item is null) + return; + + _context.MachineFamilies.Remove(item); + + await _context.SaveChangesAsync(); + } } } \ No newline at end of file