2020-06-01 02:12:50 +01:00
|
|
|
/******************************************************************************
|
|
|
|
|
// MARECHAI: Master repository of computing history artifacts information
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// --[ 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
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
2020-05-24 21:50:17 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Blazorise;
|
|
|
|
|
using Marechai.ViewModels;
|
2020-06-10 00:27:39 +01:00
|
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
2020-05-24 21:50:17 +01:00
|
|
|
|
|
|
|
|
namespace Marechai.Pages.Admin
|
|
|
|
|
{
|
|
|
|
|
public partial class Machines
|
|
|
|
|
{
|
|
|
|
|
bool _deleteInProgress;
|
|
|
|
|
Modal _frmDelete;
|
2020-06-10 17:31:57 +01:00
|
|
|
bool _loaded;
|
2020-05-24 21:50:17 +01:00
|
|
|
MachineViewModel _machine;
|
|
|
|
|
List<MachineViewModel> _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;
|
2020-06-10 00:27:39 +01:00
|
|
|
AuthenticationState authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
2020-05-24 21:50:17 +01:00
|
|
|
|
|
|
|
|
// Yield thread to let UI to update
|
|
|
|
|
await Task.Yield();
|
|
|
|
|
|
2020-06-10 00:27:39 +01:00
|
|
|
await Service.DeleteAsync(_machine.Id, (await UserManager.GetUserAsync(authState.User)).Id);
|
2020-05-24 21:50:17 +01:00
|
|
|
_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;
|
|
|
|
|
|
2020-06-10 17:31:57 +01:00
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
if(_loaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_machines = await Service.GetAsync();
|
|
|
|
|
_loaded = true;
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2020-05-24 21:50:17 +01:00
|
|
|
}
|
|
|
|
|
}
|