diff --git a/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 b/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2
index 67eb224..263201a 100644
Binary files a/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 and b/Code/.vs/BlazorApp/DesignTimeBuild/.dtbcache.v2 differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/0a99a780-ecbb-4e02-a14c-db5ac2d1b8ee.vsidx b/Code/.vs/BlazorApp/FileContentIndex/0a99a780-ecbb-4e02-a14c-db5ac2d1b8ee.vsidx
deleted file mode 100644
index 7b5e8f0..0000000
Binary files a/Code/.vs/BlazorApp/FileContentIndex/0a99a780-ecbb-4e02-a14c-db5ac2d1b8ee.vsidx and /dev/null differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/0af5044c-bef7-4346-b366-592a44262888.vsidx b/Code/.vs/BlazorApp/FileContentIndex/0af5044c-bef7-4346-b366-592a44262888.vsidx
new file mode 100644
index 0000000..ec655b9
Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/0af5044c-bef7-4346-b366-592a44262888.vsidx differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/20f2056d-3dd2-4d67-abea-b0db76f01ce8.vsidx b/Code/.vs/BlazorApp/FileContentIndex/20f2056d-3dd2-4d67-abea-b0db76f01ce8.vsidx
new file mode 100644
index 0000000..d238dc3
Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/20f2056d-3dd2-4d67-abea-b0db76f01ce8.vsidx differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/3fc398b1-4ba7-4baf-976e-74849c746312.vsidx b/Code/.vs/BlazorApp/FileContentIndex/3fc398b1-4ba7-4baf-976e-74849c746312.vsidx
deleted file mode 100644
index 46c7c66..0000000
Binary files a/Code/.vs/BlazorApp/FileContentIndex/3fc398b1-4ba7-4baf-976e-74849c746312.vsidx and /dev/null differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/75ffb243-1a00-47cb-ab2f-9702e28b45f1.vsidx b/Code/.vs/BlazorApp/FileContentIndex/75ffb243-1a00-47cb-ab2f-9702e28b45f1.vsidx
deleted file mode 100644
index ab72ac0..0000000
Binary files a/Code/.vs/BlazorApp/FileContentIndex/75ffb243-1a00-47cb-ab2f-9702e28b45f1.vsidx and /dev/null differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/097f023e-c76e-4132-87f1-fcb77a998335.vsidx b/Code/.vs/BlazorApp/FileContentIndex/c179d6a2-70d8-4aa5-867e-2005e336945c.vsidx
similarity index 96%
rename from Code/.vs/BlazorApp/FileContentIndex/097f023e-c76e-4132-87f1-fcb77a998335.vsidx
rename to Code/.vs/BlazorApp/FileContentIndex/c179d6a2-70d8-4aa5-867e-2005e336945c.vsidx
index 2eb8421..88c5efc 100644
Binary files a/Code/.vs/BlazorApp/FileContentIndex/097f023e-c76e-4132-87f1-fcb77a998335.vsidx and b/Code/.vs/BlazorApp/FileContentIndex/c179d6a2-70d8-4aa5-867e-2005e336945c.vsidx differ
diff --git a/Code/.vs/BlazorApp/FileContentIndex/c1df8f8e-04e1-462d-9962-7d15a3c47436.vsidx b/Code/.vs/BlazorApp/FileContentIndex/c1df8f8e-04e1-462d-9962-7d15a3c47436.vsidx
new file mode 100644
index 0000000..6a76e22
Binary files /dev/null and b/Code/.vs/BlazorApp/FileContentIndex/c1df8f8e-04e1-462d-9962-7d15a3c47436.vsidx differ
diff --git a/Code/.vs/BlazorApp/v17/.futdcache.v2 b/Code/.vs/BlazorApp/v17/.futdcache.v2
new file mode 100644
index 0000000..ab07074
Binary files /dev/null and b/Code/.vs/BlazorApp/v17/.futdcache.v2 differ
diff --git a/Code/.vs/BlazorApp/v17/.suo b/Code/.vs/BlazorApp/v17/.suo
index 2a9f57c..ee66a22 100644
Binary files a/Code/.vs/BlazorApp/v17/.suo and b/Code/.vs/BlazorApp/v17/.suo differ
diff --git a/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 b/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2
new file mode 100644
index 0000000..1bc4002
Binary files /dev/null and b/Code/.vs/ProjectEvaluation/blazorapp.metadata.v5.2 differ
diff --git a/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 b/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2
new file mode 100644
index 0000000..9b79928
Binary files /dev/null and b/Code/.vs/ProjectEvaluation/blazorapp.projects.v5.2 differ
diff --git a/Code/BlazorApp.sln b/Code/BlazorApp.sln
index 8de0c5d..2d8511f 100644
--- a/Code/BlazorApp.sln
+++ b/Code/BlazorApp.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjetBlazor", "ProjetBlazor\ProjetBlazor.csproj", "{D63FE586-7854-4213-BB93-F39ABD37994C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjetBlazor", "ProjetBlazor\ProjetBlazor.csproj", "{D63FE586-7854-4213-BB93-F39ABD37994C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Code/ProjetBlazor/Models/Item.cs b/Code/ProjetBlazor/Models/Item.cs
index b5791c7..0f5dccd 100644
--- a/Code/ProjetBlazor/Models/Item.cs
+++ b/Code/ProjetBlazor/Models/Item.cs
@@ -7,8 +7,8 @@
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 List EnchantCategories { get; set; }
+ public List RepairWith { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
}
diff --git a/Code/ProjetBlazor/Models/ItemModel.cs b/Code/ProjetBlazor/Models/ItemModel.cs
new file mode 100644
index 0000000..eea6f5a
--- /dev/null
+++ b/Code/ProjetBlazor/Models/ItemModel.cs
@@ -0,0 +1,38 @@
+using System.ComponentModel.DataAnnotations;
+
+namespace ProjetBlazor.Models
+{
+ public class ItemModel
+ {
+ public int Id { get; set; }
+
+ [Required]
+ [StringLength(50, ErrorMessage = "Le nom affiché ne doit pas dépasser 50 caractères.")]
+ public string? DisplayName { get; set; }
+
+ [Required]
+ [StringLength(50, ErrorMessage = "Le nom ne doit pas dépasser 50 caractères.")]
+ [RegularExpression(@"^[a-z''-'\s]{1,40}$", ErrorMessage = "Seulement les caractères en minuscule sont acceptées.")]
+ 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 = "Vous devez accepter les conditions.")]
+ public bool AcceptCondition { get; set; }
+
+ [Required(ErrorMessage = "L'image de l'item est obligatoire !")]
+ public byte[]? ImageContent { get; set; }
+ }
+}
+
diff --git a/Code/ProjetBlazor/Pages/Add.razor b/Code/ProjetBlazor/Pages/Add.razor
new file mode 100644
index 0000000..bd6f66c
--- /dev/null
+++ b/Code/ProjetBlazor/Pages/Add.razor
@@ -0,0 +1,70 @@
+@page "/add"
+@using ProjetBlazor.Models;
+
+Add
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enchant categories:
+
+ @foreach (var item in enchantCategories)
+ {
+
+ }
+
+
+
+ Repair with:
+
+ @foreach (var item in repairWith)
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Code/ProjetBlazor/Pages/Add.razor.cs b/Code/ProjetBlazor/Pages/Add.razor.cs
new file mode 100644
index 0000000..c9f3539
--- /dev/null
+++ b/Code/ProjetBlazor/Pages/Add.razor.cs
@@ -0,0 +1,121 @@
+using Blazored.LocalStorage;
+using Microsoft.AspNetCore.Components.Forms;
+using Microsoft.AspNetCore.Components;
+using ProjetBlazor.Models;
+
+namespace ProjetBlazor.Pages
+{
+ public partial class Add
+ {
+ [Inject]
+ public ILocalStorageService LocalStorage { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ ///
+ /// The default enchant categories.
+ ///
+ private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" };
+
+ ///
+ /// 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" };
+
+ ///
+ /// The current item model
+ ///
+ private ItemModel itemModel = new()
+ {
+ EnchantCategories = new List(),
+ RepairWith = new List()
+ };
+
+ private async void HandleValidSubmit()
+ {
+ // Get the current data
+ var currentData = await LocalStorage.GetItemAsync>("data");
+
+ // Simulate the Id
+ itemModel.Id = currentData.Max(s => s.Id) + 1;
+
+ // Add the item to the current data
+ currentData.Add(new Item
+ {
+ Id = itemModel.Id,
+ DisplayName = itemModel.DisplayName,
+ Name = itemModel.Name,
+ RepairWith = itemModel.RepairWith,
+ EnchantCategories = itemModel.EnchantCategories,
+ MaxDurability = itemModel.MaxDurability,
+ StackSize = itemModel.StackSize,
+ CreatedDate = DateTime.Now
+ });
+
+ // Save the image
+ var imagePathInfo = new DirectoryInfo($"{WebHostEnvironment.WebRootPath}/images");
+
+ // Check if the folder "images" exist
+ if (!imagePathInfo.Exists)
+ {
+ imagePathInfo.Create();
+ }
+
+ // Determine the image name
+ var fileName = new FileInfo($"{imagePathInfo}/{itemModel.Name}.png");
+
+ // Write the file content
+ await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent);
+
+ // Save the data
+ await LocalStorage.SetItemAsync("data", currentData);
+ }
+
+ 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/Code/ProjetBlazor/Pages/List.razor b/Code/ProjetBlazor/Pages/List.razor
index c1cca6c..6289682 100644
--- a/Code/ProjetBlazor/Pages/List.razor
+++ b/Code/ProjetBlazor/Pages/List.razor
@@ -3,6 +3,12 @@
List
+
+
+ Ajouter
+
+
+
+
+
+ @if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{context.Name}.png"))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
diff --git a/Code/ProjetBlazor/Pages/List.razor.cs b/Code/ProjetBlazor/Pages/List.razor.cs
index 87e97a0..5b511e6 100644
--- a/Code/ProjetBlazor/Pages/List.razor.cs
+++ b/Code/ProjetBlazor/Pages/List.razor.cs
@@ -1,4 +1,5 @@
-using Blazorise.DataGrid;
+using Blazored.LocalStorage;
+using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
using ProjetBlazor.Models;
@@ -11,10 +12,35 @@ namespace ProjetBlazor.Pages
private int totalItem;
[Inject]
- public HttpClient? Http { get; set; }
+ public HttpClient Http { get; set; }
[Inject]
- public NavigationManager? NavigationManager { get; set; }
+ public ILocalStorageService LocalStorage { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { 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)
{
@@ -24,12 +50,12 @@ namespace ProjetBlazor.Pages
}
// 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 Http.GetFromJsonAsync
- ($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
+ //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 Http.GetFromJsonAsync
>($"{NavigationManager.BaseUri}fake-data.json")).Count;
+ totalItem = (await LocalStorage.GetItemAsync>("data")).Count;
items = new List- (response); // an actual data for the current page
}
}
diff --git a/Code/ProjetBlazor/Program.cs b/Code/ProjetBlazor/Program.cs
index 2347b15..79e06d2 100644
--- a/Code/ProjetBlazor/Program.cs
+++ b/Code/ProjetBlazor/Program.cs
@@ -1,8 +1,7 @@
+using Blazored.LocalStorage;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
-using Microsoft.AspNetCore.Components;
-using Microsoft.AspNetCore.Components.Web;
using ProjetBlazor.Data;
var builder = WebApplication.CreateBuilder(args);
@@ -15,6 +14,7 @@ builder.Services.AddHttpClient();
builder.Services.AddBlazorise();
builder.Services.AddBootstrapProviders();
builder.Services.AddFontAwesomeIcons();
+builder.Services.AddBlazoredLocalStorage();
var app = builder.Build();
diff --git a/Code/ProjetBlazor/ProjetBlazor.csproj b/Code/ProjetBlazor/ProjetBlazor.csproj
index ab40bde..fb1c826 100644
--- a/Code/ProjetBlazor/ProjetBlazor.csproj
+++ b/Code/ProjetBlazor/ProjetBlazor.csproj
@@ -7,6 +7,7 @@
+
diff --git a/Code/ProjetBlazor/Shared/NavMenu.razor b/Code/ProjetBlazor/Shared/NavMenu.razor
index 6794f67..3b1725e 100644
--- a/Code/ProjetBlazor/Shared/NavMenu.razor
+++ b/Code/ProjetBlazor/Shared/NavMenu.razor
@@ -1,4 +1,4 @@
-y
+
ProjetBlazor