diff --git a/App.razor b/App.razor
index 111b4cd..beba7bf 100644
--- a/App.razor
+++ b/App.razor
@@ -1,4 +1,5 @@
-
+
+
@@ -6,3 +7,4 @@
Sorry, there's nothing at this address.
+
\ No newline at end of file
diff --git a/Factories/ItemFactory.cs.cs b/Factories/ItemFactory.cs.cs
new file mode 100644
index 0000000..c07693f
--- /dev/null
+++ b/Factories/ItemFactory.cs.cs
@@ -0,0 +1,48 @@
+using ProjetBlaser.Models;
+
+namespace ProjetBlaser.Factories
+{
+ public static class ItemFactory
+ {
+ public static ItemModel ToModel(Item item, byte[] imageContent)
+ {
+ return new ItemModel
+ {
+ Id = item.Id,
+ DisplayName = item.DisplayName,
+ Name = item.Name,
+ RepairWith = item.RepairWith,
+ EnchantCategories = item.EnchantCategories,
+ MaxDurability = item.MaxDurability,
+ StackSize = item.StackSize,
+ ImageContent = imageContent
+ };
+ }
+
+ public static Item Create(ItemModel model)
+ {
+ return new Item
+ {
+ Id = model.Id,
+ DisplayName = model.DisplayName,
+ Name = model.Name,
+ RepairWith = model.RepairWith,
+ EnchantCategories = model.EnchantCategories,
+ MaxDurability = model.MaxDurability,
+ StackSize = model.StackSize,
+ CreatedDate = DateTime.Now
+ };
+ }
+
+ public static void Update(Item item, ItemModel model)
+ {
+ item.DisplayName = model.DisplayName;
+ item.Name = model.Name;
+ item.RepairWith = model.RepairWith;
+ item.EnchantCategories = model.EnchantCategories;
+ item.MaxDurability = model.MaxDurability;
+ item.StackSize = model.StackSize;
+ item.UpdatedDate = DateTime.Now;
+ }
+ }
+}
diff --git a/Pages/Edit.razor b/Pages/Edit.razor
index d201ae0..3512c00 100644
--- a/Pages/Edit.razor
+++ b/Pages/Edit.razor
@@ -1,3 +1,82 @@
@page "/edit/{Id:int}"
+
Edit
-Mon paramètre: @Id
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enchant categories:
+
+ @foreach (var item in enchantCategories)
+ {
+
+ }
+
+
+
+ Repair with:
+
+ @foreach (var item in repairWith)
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Pages/Edit.razor.cs b/Pages/Edit.razor.cs
index 39df9c7..ff58b5f 100644
--- a/Pages/Edit.razor.cs
+++ b/Pages/Edit.razor.cs
@@ -1,10 +1,123 @@
using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
+using ProjetBlaser.Factories;
+using ProjetBlaser.Models;
+using ProjetBlaser.Services;
namespace ProjetBlaser.Pages
{
+
+
public partial class Edit
{
[Parameter]
public int Id { get; set; }
+
+ ///
+ /// 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; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ protected override async Task OnInitializedAsync()
+ {
+ var item = await DataService.GetById(Id);
+
+ var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png");
+
+ if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png"))
+ {
+ fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.Name}.png");
+ }
+
+ // Set the model with the item
+ itemModel = new ItemModel
+ {
+ Id = item.Id,
+ DisplayName = item.DisplayName,
+ Name = item.Name,
+ RepairWith = item.RepairWith,
+ EnchantCategories = item.EnchantCategories,
+ MaxDurability = item.MaxDurability,
+ StackSize = item.StackSize,
+ ImageContent = fileContent
+ };
+ itemModel = ItemFactory.ToModel(item, fileContent);
+ }
+
+ private async void HandleValidSubmit()
+ {
+ await DataService.Update(Id, 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);
+ }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/Pages/List.razor b/Pages/List.razor
index 7b223e8..4abdf7a 100644
--- a/Pages/List.razor
+++ b/Pages/List.razor
@@ -44,6 +44,7 @@
Editer
+
\ No newline at end of file
diff --git a/Pages/List.razor.cs b/Pages/List.razor.cs
index c71334b..6c0e92e 100644
--- a/Pages/List.razor.cs
+++ b/Pages/List.razor.cs
@@ -31,5 +31,9 @@ namespace ProjetBlaser.Pages
totalItem = await DataService.Count();
}
}
+ private void OnDelete(int id)
+ {
+
+ }
}
}
diff --git a/Pages/ParameterParen.razor b/Pages/ParameterParen.razor
index 7b5ae80..66aacb0 100644
--- a/Pages/ParameterParen.razor
+++ b/Pages/ParameterParen.razor
@@ -1,4 +1,5 @@
@page "/parameter-parent"
+@using ProjetBlaser.Models
Child component (without attribute values)
diff --git a/Pages/User.razor b/Pages/User.razor
index 907e345..d08987f 100644
--- a/Pages/User.razor
+++ b/Pages/User.razor
@@ -1,4 +1,4 @@
-@page "/user/{Id:int}/{Option:bool?}"
+@page "/user/{Id:int}"
Id: @Id
diff --git a/Pages/_Layout.cshtml b/Pages/_Layout.cshtml
index 73357e2..b7ebeb0 100644
--- a/Pages/_Layout.cshtml
+++ b/Pages/_Layout.cshtml
@@ -29,7 +29,9 @@
+
+