mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add code to delete machine families.
This commit is contained in:
@@ -1,63 +0,0 @@
|
|||||||
@{
|
|
||||||
/******************************************************************************
|
|
||||||
// MARECHAI: Master repository of computing history artifacts information
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// Filename : Delete.cshtml
|
|
||||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
||||||
//
|
|
||||||
// --[ 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 <http://www.gnu.org/licenses/>.
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
// Copyright © 2003-2020 Natalia Portillo
|
|
||||||
*******************************************************************************/
|
|
||||||
}
|
|
||||||
@model Marechai.Database.Models.MachineFamily
|
|
||||||
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Delete";
|
|
||||||
}
|
|
||||||
<h2>Delete</h2>
|
|
||||||
<h3>Are you sure you want to delete this?</h3>
|
|
||||||
<div>
|
|
||||||
<h4>Machine family</h4>
|
|
||||||
<hr />
|
|
||||||
<dl class="dl-horizontal">
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Company)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Company.Name)
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
@Html.DisplayNameFor(model => model.Name)
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
@Html.DisplayFor(model => model.Name)
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
<form asp-action="Delete">
|
|
||||||
<input type="hidden" asp-for="Id" />
|
|
||||||
<input class="btn btn-danger" type="submit" value="Delete" />
|
|
||||||
<a asp-action="Index" class="btn btn-secondary">
|
|
||||||
Back to List
|
|
||||||
</a>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
@@ -31,7 +31,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@page "/admin/machine_families"
|
@page "/admin/machine_families"
|
||||||
@using Marechai.Database.Models
|
|
||||||
@inherits OwningComponentBase<MachineFamiliesService>
|
@inherits OwningComponentBase<MachineFamiliesService>
|
||||||
@inject IStringLocalizer<MachineFamiliesService> L
|
@inject IStringLocalizer<MachineFamiliesService> L
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
@@ -76,21 +75,26 @@
|
|||||||
<span class="btn btn-secondary">
|
<span class="btn btn-secondary">
|
||||||
@L["Edit"]
|
@L["Edit"]
|
||||||
</span>
|
</span>
|
||||||
<span class="btn btn-danger">
|
<Button Color="Color.Danger" Clicked="() => {ShowModal(item.Id);}">@L["Delete"]</Button>
|
||||||
@L["Delete"]
|
|
||||||
</span>
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
@code
|
<Modal @ref="_frmDelete" IsCentered="true" Closing="@ModalClosing">
|
||||||
{
|
<ModalBackdrop/>
|
||||||
List<MachineFamilyViewModel> _machineFamilies;
|
<ModalContent Centered="true">
|
||||||
|
<ModalHeader>
|
||||||
protected override async Task OnInitializedAsync()
|
<ModalTitle>@L["Delete machine family"]</ModalTitle>
|
||||||
{
|
<CloseButton Clicked="@HideModal"/>
|
||||||
_machineFamilies = await Service.GetAsync();
|
</ModalHeader>
|
||||||
}
|
<ModalBody>
|
||||||
}
|
<Text>@string.Format(@L["Are you sure you want to delete {0} {1}?"], _machineFamily?.Company, _machineFamily?.Name)</Text>
|
||||||
|
</ModalBody>
|
||||||
|
<ModalFooter>
|
||||||
|
<Button Color="Color.Primary" Clicked="@HideModal" Disabled="@_deleteInProgress">@L["Cancel"]</Button>
|
||||||
|
<Button Color="Color.Danger" Clicked="@ConfirmDelete" Disabled="@_deleteInProgress">@L["Delete"]</Button>
|
||||||
|
</ModalFooter>
|
||||||
|
</ModalContent>
|
||||||
|
</Modal>
|
||||||
|
|||||||
52
Marechai/Pages/Admin/MachineFamilies.razor.cs
Normal file
52
Marechai/Pages/Admin/MachineFamilies.razor.cs
Normal file
@@ -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<MachineFamilyViewModel> _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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -150,4 +150,16 @@
|
|||||||
<value>Eliminar</value>
|
<value>Eliminar</value>
|
||||||
<comment>Delete</comment>
|
<comment>Delete</comment>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Delete machine family" xml:space="preserve">
|
||||||
|
<value>Eliminar familia de máquinas</value>
|
||||||
|
<comment>Delete machine family</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Are you sure you want to delete {0} {1}?" xml:space="preserve">
|
||||||
|
<value>¿Está seguro de que desea borrar {0} {1}?</value>
|
||||||
|
<comment>{0} company name, {1} family name</comment>
|
||||||
|
</data>
|
||||||
|
<data name="Cancel" xml:space="preserve">
|
||||||
|
<value>Cancelar</value>
|
||||||
|
<comment>Cancel</comment>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
@@ -19,5 +19,17 @@ namespace Marechai.Services
|
|||||||
{
|
{
|
||||||
Id = m.Id, Company = m.Company.Name, Name = m.Name
|
Id = m.Id, Company = m.Company.Name, Name = m.Name
|
||||||
}).ToListAsync();
|
}).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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user