|
|
@ -2,8 +2,12 @@
|
|
|
|
using Blazorise;
|
|
|
|
using Blazorise;
|
|
|
|
using Blazorise.DataGrid;
|
|
|
|
using Blazorise.DataGrid;
|
|
|
|
using HeartTrack.Models;
|
|
|
|
using HeartTrack.Models;
|
|
|
|
|
|
|
|
using HeartTrack.Services.TicketDataService;
|
|
|
|
|
|
|
|
using HeartTrack.Services.UserDataService;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
using Microsoft.Extensions.Localization;
|
|
|
|
|
|
|
|
using static MudBlazor.CategoryTypes;
|
|
|
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
|
|
|
|
|
|
|
namespace HeartTrack.Pages
|
|
|
|
namespace HeartTrack.Pages
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -13,37 +17,15 @@ namespace HeartTrack.Pages
|
|
|
|
|
|
|
|
|
|
|
|
private int totalUser;
|
|
|
|
private int totalUser;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public HttpClient Http { get; set; }
|
|
|
|
public HttpClient Http { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
public NavigationManager NavigationManager { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public ILocalStorageService LocalStorage { get; set; }
|
|
|
|
public ILocalStorageService LocalStorage { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
[Inject]
|
|
|
|
public IStringLocalizer<BannedUsers> Localizer { get; set; }
|
|
|
|
public IUserDataService UserService { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
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<User[]>("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<User[]>($"{NavigationManager.BaseUri}fake-data.json").Result;
|
|
|
|
|
|
|
|
await LocalStorage.SetItemAsync("data", originalData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
|
|
|
|
private async Task OnReadData(DataGridReadDataEventArgs<User> e)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -53,14 +35,24 @@ namespace HeartTrack.Pages
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// When you use a real API, we use this follow code
|
|
|
|
// When you use a real API, we use this follow code
|
|
|
|
//var response = await Http.GetJsonAsync<Data[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
|
|
|
|
//var response = await Http.GetJsonAsync<Item[]>( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
|
|
|
|
var response = (await LocalStorage.GetItemAsync<User[]>("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
|
|
|
|
var response = (await Http.GetFromJsonAsync<User[]>($"{NavigationManager.BaseUri}fake-users.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
|
|
|
|
|
|
|
|
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
|
|
if (!e.CancellationToken.IsCancellationRequested)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
totalUser = (await LocalStorage.GetItemAsync<List<User>>("data")).Count;
|
|
|
|
totalUser = (await Http.GetFromJsonAsync<List<User>>($"{NavigationManager.BaseUri}fake-users.json")).Count;
|
|
|
|
users = new List<User>(response); // an actual data for the current page
|
|
|
|
users = new List<User>(response); // an actual data for the current page
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void BanOnID(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UserService.BanOnId(id);
|
|
|
|
|
|
|
|
NavigationManager.NavigateTo("/banned-users", true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void UnbanOnID(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
UserService.UnbanOnId(id);
|
|
|
|
|
|
|
|
NavigationManager.NavigateTo("/banned-users", true);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|