From 309745e2bb1e25e5d6eb81c13bf989aabd1929b8 Mon Sep 17 00:00:00 2001 From: Nicolas FRANCO Date: Tue, 25 Oct 2022 12:02:43 +0200 Subject: [PATCH] use data --- BlazorTp1/Models/Items.cs | 15 ++ BlazorTp1/Pages/List.razor | 8 +- BlazorTp1/Pages/List.razor.cs | 17 ++- BlazorTp1/Program.cs | 2 + BlazorTp1/wwwroot/fake-data.json | 231 ++++++++++++++++++++++++++++++- 5 files changed, 270 insertions(+), 3 deletions(-) create mode 100644 BlazorTp1/Models/Items.cs 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 b/BlazorTp1/Pages/List.razor index d81cfab..1330943 100644 --- a/BlazorTp1/Pages/List.razor +++ b/BlazorTp1/Pages/List.razor @@ -2,4 +2,10 @@

List

- +@if (items != null) +{ + foreach (var item in items) + { +
@item.Id
+ } +} diff --git a/BlazorTp1/Pages/List.razor.cs b/BlazorTp1/Pages/List.razor.cs index 43c398a..cceec71 100644 --- a/BlazorTp1/Pages/List.razor.cs +++ b/BlazorTp1/Pages/List.razor.cs @@ -1,6 +1,21 @@ -namespace BlazorTp1.Pages +using Microsoft.AspNetCore.Components; +using BlazorTp1.Models; + +namespace BlazorTp1.Pages { public partial class List { + private Items[] items; + + [Inject] + public HttpClient Http { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + protected override async Task OnInitializedAsync() + { + items = await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json"); + } } } diff --git a/BlazorTp1/Program.cs b/BlazorTp1/Program.cs index 3b72458..5658049 100644 --- a/BlazorTp1/Program.cs +++ b/BlazorTp1/Program.cs @@ -9,6 +9,8 @@ builder.Services.AddRazorPages(); builder.Services.AddServerSideBlazor(); builder.Services.AddSingleton(); +builder.Services.AddHttpClient(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/BlazorTp1/wwwroot/fake-data.json b/BlazorTp1/wwwroot/fake-data.json index 0db3279..15c17d7 100644 --- a/BlazorTp1/wwwroot/fake-data.json +++ b/BlazorTp1/wwwroot/fake-data.json @@ -1,3 +1,232 @@ { - + [ + { + "id": 1, + "displayname": "Mazuda", + "name": "mazuda", + "stacksize": 48, + "maxdurability": 55, + "enchantcategories": [ + "armor_chest", + "weapon" + ], + "repairwith": [ + "dark_oak_planks", + "crimson_planks" + ], + "createddate": "2015-05-08", + "updateddate": null + }, + { + "id": 2, + "displayname": "Codact", + "name": "codact", + "stacksize": 57, + "maxdurability": 34, + "enchantcategories": [ + "breakable", + "armor_head" + ], + "repairwith": [ + "spruce_planks", + "warped_planks" + ], + "createddate": "2022-06-23", + "updateddate": "2016-06-10" + }, + { + "id": 3, + "displayname": "Delphide", + "name": "delphide", + "stacksize": 49, + "maxdurability": 94, + "enchantcategories": [ + "digger" + ], + "repairwith": [ + "acacia_planks" + ], + "createddate": "2015-01-19", + "updateddate": "2020-06-30" + }, + { + "id": 4, + "displayname": "Obones", + "name": "obones", + "stacksize": 50, + "maxdurability": 5, + "enchantcategories": [ + "breakable", + "armor", + "weapon" + ], + "repairwith": [ + "spruce_planks" + ], + "createddate": "2017-12-17", + "updateddate": null + }, + { + "id": 5, + "displayname": "Amril", + "name": "amril", + "stacksize": 32, + "maxdurability": 76, + "enchantcategories": [ + "armor", + "weapon", + "digger" + ], + "repairwith": [], + "createddate": "2015-10-18", + "updateddate": null + }, + { + "id": 6, + "displayname": "Quiltigen", + "name": "quiltigen", + "stacksize": 64, + "maxdurability": 6, + "enchantcategories": [ + "digger" + ], + "repairwith": [], + "createddate": "2014-03-01", + "updateddate": null + }, + { + "id": 7, + "displayname": "Optique", + "name": "optique", + "stacksize": 54, + "maxdurability": 112, + "enchantcategories": [ + "armor_chest", + "armor", + "digger" + ], + "repairwith": [], + "createddate": "2017-09-23", + "updateddate": "2017-04-16" + }, + { + "id": 8, + "displayname": "Digigene", + "name": "digigene", + "stacksize": 1, + "maxdurability": 98, + "enchantcategories": [], + "repairwith": [], + "createddate": "2014-02-08", + "updateddate": null + }, + { + "id": 9, + "displayname": "Exospeed", + "name": "exospeed", + "stacksize": 19, + "maxdurability": 16, + "enchantcategories": [ + "armor_chest", + "armor", + "armor" + ], + "repairwith": [ + "warped_planks" + ], + "createddate": "2017-01-27", + "updateddate": "2019-09-30" + }, + { + "id": 10, + "displayname": "Zillidium", + "name": "zillidium", + "stacksize": 23, + "maxdurability": 37, + "enchantcategories": [], + "repairwith": [ + "birch_planks", + "crimson_planks" + ], + "createddate": "2016-07-15", + "updateddate": "2018-05-16" + }, + { + "id": 11, + "displayname": "Menbrain", + "name": "menbrain", + "stacksize": 43, + "maxdurability": 52, + "enchantcategories": [ + "vanishable" + ], + "repairwith": [], + "createddate": "2014-11-29", + "updateddate": "2014-01-02" + }, + { + "id": 12, + "displayname": "Accufarm", + "name": "accufarm", + "stacksize": 22, + "maxdurability": 88, + "enchantcategories": [ + "armor_chest" + ], + "repairwith": [ + "spruce_planks", + "spruce_planks" + ], + "createddate": "2018-11-02", + "updateddate": "2016-10-31" + }, + { + "id": 13, + "displayname": "Interfind", + "name": "interfind", + "stacksize": 35, + "maxdurability": 51, + "enchantcategories": [], + "repairwith": [ + "spruce_planks", + "warped_planks" + ], + "createddate": "2020-01-16", + "updateddate": null + }, + { + "id": 14, + "displayname": "Zolarity", + "name": "zolarity", + "stacksize": 29, + "maxdurability": 55, + "enchantcategories": [ + "weapon", + "breakable", + "armor_head" + ], + "repairwith": [ + "spruce_planks" + ], + "createddate": "2016-03-19", + "updateddate": "2018-10-10" + }, + { + "id": 15, + "displayname": "Kangle", + "name": "kangle", + "stacksize": 20, + "maxdurability": 64, + "enchantcategories": [ + "vanishable", + "armor_head", + "armor" + ], + "repairwith": [ + "dark_oak_planks" + ], + "createddate": "2014-08-13", + "updateddate": null + } + ] }