diff --git a/.idea/.idea.TP Blazor/.idea/indexLayout.xml b/.idea/.idea.TP Blazor/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.TP Blazor/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.TP Blazor/.idea/vcs.xml b/.idea/.idea.TP Blazor/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/.idea.TP Blazor/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..522c4a2 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/TP Blazor/TP Blazor.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/TP Blazor/TP Blazor.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/TP Blazor/TP Blazor.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/TP Blazor/Pages/Add.razor b/TP Blazor/Pages/Add.razor new file mode 100644 index 0000000..d696ca7 --- /dev/null +++ b/TP Blazor/Pages/Add.razor @@ -0,0 +1,72 @@ +@page "/add" + +

Add

+ + + +

+ +

+

+ +

+

+ +

+

+ +

+

+ Enchant categories: +

+ @foreach (var item in enchantCategories) + { + + } +
+

+

+ Repair with: +

+ @foreach (var item in repairWith) + { + + } +
+

+

+ +

+

+ +

+ + + +
+ + + diff --git a/TP Blazor/Pages/Add.razor.cs b/TP Blazor/Pages/Add.razor.cs new file mode 100644 index 0000000..8f7cf02 --- /dev/null +++ b/TP Blazor/Pages/Add.razor.cs @@ -0,0 +1,116 @@ +using System; +using System.Security.Cryptography; +using Blazored.LocalStorage; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Forms; +using TP_Blazor.Models; +using TP_Blazor.Services; + +namespace TP_Blazor.Pages; + +public partial class Add +{ + [Inject] + ILocalStorageService LocalStorage { get; set; } + + [Inject] + IWebHostEnvironment WebHostEnvironment { get; set; } + + [Inject] + public NavigationManager NavigationManager { get; set; } + + private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" }; + private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" }; + + [Inject] + private IDataService DataService{ get; set; } + + + + + private ItemModel itemModel = new() + { + EnchantCategories = new List(), + RepairWith = new List() + }; + + private async void OnHandleValidSubmit() + { + /*var currentData = await LocalStorage.GetItemAsync>("data"); + itemModel.Id = currentData.Max(s => s.Id) + 1; + 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 + }); + + var imagePathInfo = new DirectoryInfo($"{WebHostEnvironment.WebRootPath}/images"); + + if (!imagePathInfo.Exists) + { + imagePathInfo.Create(); + } + + var fileName = new FileInfo($"{imagePathInfo}/{itemModel.Name}.png"); + await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent); + + await LocalStorage.SetItemAsync("data", currentData); + NavigationManager.NavigateTo("list");*/ + await DataService.Add(itemModel); + NavigationManager.NavigateTo("list"); + } + + private async Task LoadImage(InputFileChangeEventArgs e) + { + + 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/TP Blazor/wwwroot/images/default.png b/TP Blazor/wwwroot/images/default.png new file mode 100644 index 0000000..a7446c9 Binary files /dev/null and b/TP Blazor/wwwroot/images/default.png differ