|
|
|
@ -1,6 +1,14 @@
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
using Blazorise.DataGrid;
|
|
|
|
|
using Blazor.ViewClasses;
|
|
|
|
|
using Blazor.Modals;
|
|
|
|
|
using Blazor.Models;
|
|
|
|
|
using Blazored.LocalStorage;
|
|
|
|
|
using Blazored.Modal.Services;
|
|
|
|
|
using Blazor.Modals;
|
|
|
|
|
using Blazor.Services;
|
|
|
|
|
using Blazored.Modal;
|
|
|
|
|
using Blazored.Modal;
|
|
|
|
|
|
|
|
|
|
namespace Blazor.Pages.Admins;
|
|
|
|
|
|
|
|
|
@ -9,6 +17,17 @@ public partial class Administrators
|
|
|
|
|
public List<Administrator> administrators;
|
|
|
|
|
|
|
|
|
|
private int totalItem;
|
|
|
|
|
[CascadingParameter]
|
|
|
|
|
public IModalService Modal { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IDataService DataService { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public IWebHostEnvironment WebHostEnvironment { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ILocalStorageService LocalStorage { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public HttpClient Http { get; set; }
|
|
|
|
@ -33,4 +52,42 @@ public partial class Administrators
|
|
|
|
|
administrators = new List<Administrator>(response); // an actual data for the current page
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
|
|
|
{
|
|
|
|
|
// Do not treat this action if is not the first render
|
|
|
|
|
if (!firstRender)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentData = await LocalStorage.GetItemAsync<AdministratorsModel[]>("data");
|
|
|
|
|
|
|
|
|
|
// Check if data exist in the local storage
|
|
|
|
|
if (currentData == null)
|
|
|
|
|
{
|
|
|
|
|
// this code add in the local storage the fake data (we load the data sync for initialize the data before load the OnReadData method)
|
|
|
|
|
var originalData = Http.GetFromJsonAsync<AdministratorsModel[]>($"trusting-panini.87-106-126-109.plesk.page/api/chapters").Result;
|
|
|
|
|
await LocalStorage.SetItemAsync("data", originalData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async void OnDelete(int id)
|
|
|
|
|
{
|
|
|
|
|
var parameters = new ModalParameters();
|
|
|
|
|
parameters.Add(nameof(Administrator.Id), id);
|
|
|
|
|
|
|
|
|
|
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
|
|
|
|
|
var result = modal.Result;
|
|
|
|
|
|
|
|
|
|
if (result.IsCanceled)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await DataService.Delete(id);
|
|
|
|
|
|
|
|
|
|
// Reload the page
|
|
|
|
|
NavigationManager.NavigateTo("administrators", true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|