diff --git a/.vs/Blazor/v17/.suo b/.vs/Blazor/v17/.suo
index c7a175e..4869c96 100644
Binary files a/.vs/Blazor/v17/.suo and b/.vs/Blazor/v17/.suo differ
diff --git a/.vs/BlazorApp1/DesignTimeBuild/.dtbcache.v2 b/.vs/BlazorApp1/DesignTimeBuild/.dtbcache.v2
index ab9ede5..e6e52b7 100644
Binary files a/.vs/BlazorApp1/DesignTimeBuild/.dtbcache.v2 and b/.vs/BlazorApp1/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/.vs/BlazorApp1/FileContentIndex/18e79921-6773-40b0-839c-9340e29b62e1.vsidx b/.vs/BlazorApp1/FileContentIndex/18e79921-6773-40b0-839c-9340e29b62e1.vsidx
new file mode 100644
index 0000000..3284a0d
Binary files /dev/null and b/.vs/BlazorApp1/FileContentIndex/18e79921-6773-40b0-839c-9340e29b62e1.vsidx differ
diff --git a/.vs/BlazorApp1/FileContentIndex/4a2908b6-4493-4b5f-b32a-d23319d1ad92.vsidx b/.vs/BlazorApp1/FileContentIndex/4a2908b6-4493-4b5f-b32a-d23319d1ad92.vsidx
deleted file mode 100644
index 43ffb43..0000000
Binary files a/.vs/BlazorApp1/FileContentIndex/4a2908b6-4493-4b5f-b32a-d23319d1ad92.vsidx and /dev/null differ
diff --git a/.vs/BlazorApp1/FileContentIndex/5fa0b557-f3d5-4cef-a14a-2fee3069558b.vsidx b/.vs/BlazorApp1/FileContentIndex/5fa0b557-f3d5-4cef-a14a-2fee3069558b.vsidx
deleted file mode 100644
index 05c1f4c..0000000
Binary files a/.vs/BlazorApp1/FileContentIndex/5fa0b557-f3d5-4cef-a14a-2fee3069558b.vsidx and /dev/null differ
diff --git a/.vs/BlazorApp1/FileContentIndex/90f77c1b-4a07-4611-8ce6-b64cbccc1336.vsidx b/.vs/BlazorApp1/FileContentIndex/90f77c1b-4a07-4611-8ce6-b64cbccc1336.vsidx
deleted file mode 100644
index 237cf80..0000000
Binary files a/.vs/BlazorApp1/FileContentIndex/90f77c1b-4a07-4611-8ce6-b64cbccc1336.vsidx and /dev/null differ
diff --git a/.vs/BlazorApp1/FileContentIndex/9594cce6-891d-4f0d-b045-e9a4da3276e5.vsidx b/.vs/BlazorApp1/FileContentIndex/9594cce6-891d-4f0d-b045-e9a4da3276e5.vsidx
new file mode 100644
index 0000000..0defccd
Binary files /dev/null and b/.vs/BlazorApp1/FileContentIndex/9594cce6-891d-4f0d-b045-e9a4da3276e5.vsidx differ
diff --git a/.vs/BlazorApp1/FileContentIndex/96ff63ed-84b1-4be9-894c-2b151224e050.vsidx b/.vs/BlazorApp1/FileContentIndex/96ff63ed-84b1-4be9-894c-2b151224e050.vsidx
new file mode 100644
index 0000000..477bae7
Binary files /dev/null and b/.vs/BlazorApp1/FileContentIndex/96ff63ed-84b1-4be9-894c-2b151224e050.vsidx differ
diff --git a/.vs/BlazorApp1/FileContentIndex/c14a561e-78e5-4a07-8e16-7d354b0a13d4.vsidx b/.vs/BlazorApp1/FileContentIndex/c14a561e-78e5-4a07-8e16-7d354b0a13d4.vsidx
deleted file mode 100644
index 2c0f2ad..0000000
Binary files a/.vs/BlazorApp1/FileContentIndex/c14a561e-78e5-4a07-8e16-7d354b0a13d4.vsidx and /dev/null differ
diff --git a/.vs/BlazorApp1/FileContentIndex/ebae5088-3ad3-40b6-b68a-d194a9b4db2e.vsidx b/.vs/BlazorApp1/FileContentIndex/ebae5088-3ad3-40b6-b68a-d194a9b4db2e.vsidx
new file mode 100644
index 0000000..9595071
Binary files /dev/null and b/.vs/BlazorApp1/FileContentIndex/ebae5088-3ad3-40b6-b68a-d194a9b4db2e.vsidx differ
diff --git a/.vs/BlazorApp1/v17/.suo b/.vs/BlazorApp1/v17/.suo
index be7008e..b73e363 100644
Binary files a/.vs/BlazorApp1/v17/.suo and b/.vs/BlazorApp1/v17/.suo differ
diff --git a/.vs/ProjectEvaluation/blazorapp1.metadata.v2 b/.vs/ProjectEvaluation/blazorapp1.metadata.v2
index 13de483..78c0b5e 100644
Binary files a/.vs/ProjectEvaluation/blazorapp1.metadata.v2 and b/.vs/ProjectEvaluation/blazorapp1.metadata.v2 differ
diff --git a/.vs/ProjectEvaluation/blazorapp1.projects.v2 b/.vs/ProjectEvaluation/blazorapp1.projects.v2
index b7a36df..26fe1a6 100644
Binary files a/.vs/ProjectEvaluation/blazorapp1.projects.v2 and b/.vs/ProjectEvaluation/blazorapp1.projects.v2 differ
diff --git a/BlazorApp1/App.razor b/BlazorApp1/App.razor
index 623580d..b0cd24a 100644
--- a/BlazorApp1/App.razor
+++ b/BlazorApp1/App.razor
@@ -9,4 +9,4 @@
Sorry, there's nothing at this address.
-
+
\ No newline at end of file
diff --git a/BlazorApp1/BlazorApp1.csproj b/BlazorApp1/BlazorApp1.csproj
index b775b09..5a078bb 100644
--- a/BlazorApp1/BlazorApp1.csproj
+++ b/BlazorApp1/BlazorApp1.csproj
@@ -6,4 +6,11 @@
enable
+
+
+
+
+
+
+
diff --git a/BlazorApp1/Models/ItemModel.cs b/BlazorApp1/Models/ItemModel.cs
new file mode 100644
index 0000000..e4b8541
--- /dev/null
+++ b/BlazorApp1/Models/ItemModel.cs
@@ -0,0 +1,37 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace BlazorApp1.Models
+{
+ public class ItemModel
+ {
+ public int Id { get; set; }
+
+ [Required]
+ [StringLength(50, ErrorMessage = "The display name must not exceed 50 characters.")]
+ public string DisplayName { get; set; }
+
+ [Required]
+ [StringLength(50, ErrorMessage = "The name must not exceed 50 characters.")]
+ [RegularExpression(@"^[a-z''-'\s]{1,40}$", ErrorMessage = "Only lowercase characters are accepted.")]
+ public string Name { get; set; }
+
+ [Required]
+ [Range(1, 64)]
+ public int StackSize { get; set; }
+
+ [Required]
+ [Range(1, 125)]
+ public int MaxDurability { get; set; }
+
+ public List EnchantCategories { get; set; }
+
+ public List RepairWith { get; set; }
+
+ [Required]
+ [Range(typeof(bool), "true", "true", ErrorMessage = "You must agree to the terms.")]
+ public bool AcceptCondition { get; set; }
+
+ [Required(ErrorMessage = "The image of the item is mandatory!")]
+ public byte[] ImageContent { get; set; }
+ }
+}
diff --git a/BlazorApp1/Pages/Add.razor b/BlazorApp1/Pages/Add.razor
new file mode 100644
index 0000000..0ed932c
--- /dev/null
+++ b/BlazorApp1/Pages/Add.razor
@@ -0,0 +1,69 @@
+@page "/add"
+
+Add
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enchant categories:
+
+ @foreach (var item in enchantCategories)
+ {
+
+ }
+
+
+
+ Repair with:
+
+ @foreach (var item in repairWith)
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/BlazorApp1/Pages/Add.razor.cs b/BlazorApp1/Pages/Add.razor.cs
new file mode 100644
index 0000000..df123ce
--- /dev/null
+++ b/BlazorApp1/Pages/Add.razor.cs
@@ -0,0 +1,89 @@
+using BlazorApp1.Models;
+using BlazorApp1.Sevices;
+using Blazored.LocalStorage;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
+
+namespace BlazorApp1.Pages
+{
+ public partial class Add
+ {
+ ///
+ /// The default enchant categories.
+ ///
+ private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" };
+
+ ///
+ /// The current item model
+ ///
+ private ItemModel itemModel = new()
+ {
+ EnchantCategories = new List(),
+ RepairWith = new List()
+ };
+
+ ///
+ /// The default repair with.
+ ///
+ private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" };
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
+ private async void HandleValidSubmit()
+ {
+ await DataService.Add(itemModel);
+
+ NavigationManager.NavigateTo("list");
+ }
+
+ private async Task LoadImage(InputFileChangeEventArgs e)
+ {
+ // Set the content of the image to the model
+ using (var memoryStream = new MemoryStream())
+ {
+ await e.File.OpenReadStream().CopyToAsync(memoryStream);
+ itemModel.ImageContent = memoryStream.ToArray();
+ }
+ }
+
+ private void OnEnchantCategoriesChange(string item, object checkedValue)
+ {
+ if ((bool)checkedValue)
+ {
+ if (!itemModel.EnchantCategories.Contains(item))
+ {
+ itemModel.EnchantCategories.Add(item);
+ }
+
+ return;
+ }
+
+ if (itemModel.EnchantCategories.Contains(item))
+ {
+ itemModel.EnchantCategories.Remove(item);
+ }
+ }
+
+ private void OnRepairWithChange(string item, object checkedValue)
+ {
+ if ((bool)checkedValue)
+ {
+ if (!itemModel.RepairWith.Contains(item))
+ {
+ itemModel.RepairWith.Add(item);
+ }
+
+ return;
+ }
+
+ if (itemModel.RepairWith.Contains(item))
+ {
+ itemModel.RepairWith.Remove(item);
+ }
+ }
+ }
+}
diff --git a/BlazorApp1/Pages/Edit.razor b/BlazorApp1/Pages/Edit.razor
new file mode 100644
index 0000000..08eb818
--- /dev/null
+++ b/BlazorApp1/Pages/Edit.razor
@@ -0,0 +1,5 @@
+@page "/edit/{Id:int}"
+
+Edit
+
+My paremeter: @Id
\ No newline at end of file
diff --git a/BlazorApp1/Pages/Edit.razor.cs b/BlazorApp1/Pages/Edit.razor.cs
new file mode 100644
index 0000000..b557f74
--- /dev/null
+++ b/BlazorApp1/Pages/Edit.razor.cs
@@ -0,0 +1,10 @@
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp1.Pages
+{
+ public partial class Edit
+ {
+ [Parameter]
+ public int Id { get; set; }
+ }
+}
diff --git a/BlazorApp1/Pages/List.razor b/BlazorApp1/Pages/List.razor
index ebef1a3..3d32f93 100644
--- a/BlazorApp1/Pages/List.razor
+++ b/BlazorApp1/Pages/List.razor
@@ -1,11 +1,50 @@
@page "/List"
-List
+List
-@if (items != null)
-{
- foreach (var item in items)
- {
- @item.Id
- }
-}
\ No newline at end of file
+
+
+ Ajouter
+
+
+
+
+
+
+
+ @if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{context.Name}.png"))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
+
+
+
+
+ @(string.Join(", ", ((Item)context).EnchantCategories))
+
+
+
+
+ @(string.Join(", ", ((Item)context).RepairWith))
+
+
+
+
+
+ Editer
+
+
+
\ No newline at end of file
diff --git a/BlazorApp1/Pages/List.razor.cs b/BlazorApp1/Pages/List.razor.cs
index d7e4077..41e06e6 100644
--- a/BlazorApp1/Pages/List.razor.cs
+++ b/BlazorApp1/Pages/List.razor.cs
@@ -1,20 +1,90 @@
-using Microsoft.AspNetCore.Components;
+using BlazorApp1.Sevices;
+using Blazored.LocalStorage;
+using Blazorise.DataGrid;
+using Microsoft.AspNetCore.Components;
namespace BlazorApp1.Pages
{
public partial class List
{
- private Item[] items;
+ private List- items;
+
+ private int totalItem;
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ private async Task OnReadData(DataGridReadDataEventArgs
- e)
+ {
+ if (e.CancellationToken.IsCancellationRequested)
+ {
+ return;
+ }
+
+ if (!e.CancellationToken.IsCancellationRequested)
+ {
+ items = await DataService.List(e.Page, e.PageSize);
+ totalItem = await DataService.Count();
+ }
+ }
+ }
+
+ /*public partial class List
+ {
+ private List
- items;
+
+ private int totalItem;
[Inject]
public HttpClient Http { get; set; }
+ [Inject]
+ public ILocalStorageService LocalStorage { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
[Inject]
public NavigationManager NavigationManager { get; set; }
- protected override async Task OnInitializedAsync()
+ 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)
{
- items = await Http.GetFromJsonAsync
- ($"{NavigationManager.BaseUri}fake-data.json");
+ 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
+ }
}
- }
+ }*/
}
diff --git a/BlazorApp1/Pages/RouteParameter.razor b/BlazorApp1/Pages/RouteParameter.razor
new file mode 100644
index 0000000..dab9020
--- /dev/null
+++ b/BlazorApp1/Pages/RouteParameter.razor
@@ -0,0 +1,13 @@
+@page "/RouteParameter/{text?}"
+
+
Blazor is @Text!
+
+@code {
+ [Parameter]
+ public string? Text { get; set; }
+
+ protected override void OnInitialized()
+ {
+ Text = Text ?? "fantastic";
+ }
+}
\ No newline at end of file
diff --git a/BlazorApp1/Pages/_Layout.cshtml b/BlazorApp1/Pages/_Layout.cshtml
index 5a4789c..3ea60b9 100644
--- a/BlazorApp1/Pages/_Layout.cshtml
+++ b/BlazorApp1/Pages/_Layout.cshtml
@@ -28,5 +28,10 @@
+
+
+
+
+