diff --git a/BlazorTp1/Models/Items.cs b/BlazorTp1/Models/Items.cs new file mode 100644 index 0000000..d2207dd --- /dev/null +++ b/BlazorTp1/Models/Items.cs @@ -0,0 +1,15 @@ +namespace BlazorTp1.Models +{ + public class Items + { + public int Id { get; set; } + public string DisplayName { get; set; } + public string Name { get; set; } + public int StackSize { get; set; } + public int MaxDurability { get; set; } + public List EnchantCategories { get; set; } + public List RepairWith { get; set; } + public DateTime CreatedDate { get; set; } + public DateTime? UpdatedDate { get; set; } + } +} diff --git a/BlazorTp1/Pages/List.razor.cs b/BlazorTp1/Pages/List.razor.cs index b41aa67..c903133 100644 --- a/BlazorTp1/Pages/List.razor.cs +++ b/BlazorTp1/Pages/List.razor.cs @@ -7,54 +7,5 @@ namespace BlazorTp1.Pages { public partial class List { - private List items; - - private int totalItem; - - [Inject] - public HttpClient Http { get; set; } - - [Inject] - public ILocalStorageService LocalStorage { get; set; } - - [Inject] - public NavigationManager NavigationManager { 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("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($"{NavigationManager.BaseUri}fake-data.json").Result; - await LocalStorage.SetItemAsync("data", originalData); - } - } - - private async Task OnReadData(DataGridReadDataEventArgs e) - { - if (e.CancellationToken.IsCancellationRequested) - { - return; - } - - // When you use a real API, we use this follow code - //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" ); - var response = (await LocalStorage.GetItemAsync("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList(); - - if (!e.CancellationToken.IsCancellationRequested) - { - totalItem = (await LocalStorage.GetItemAsync>("data")).Count; - items = new List(response); // an actual data for the current page - } - } } }