From 8e50eb530692e179ed11c7b7a43e3b1163debd0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20P=C3=A9rez=20Ngounou?= Date: Sun, 15 Jan 2023 03:28:26 +0100 Subject: [PATCH] Commit --- .idea/.idea.TP Blazor/.idea/indexLayout.xml | 8 ++ .idea/.idea.TP Blazor/.idea/vcs.xml | 6 + .vscode/tasks.json | 41 +++++++ TP Blazor/Pages/Add.razor | 72 ++++++++++++ TP Blazor/Pages/Add.razor.cs | 116 ++++++++++++++++++++ TP Blazor/wwwroot/images/default.png | Bin 0 -> 2267 bytes 6 files changed, 243 insertions(+) create mode 100644 .idea/.idea.TP Blazor/.idea/indexLayout.xml create mode 100644 .idea/.idea.TP Blazor/.idea/vcs.xml create mode 100644 .vscode/tasks.json create mode 100644 TP Blazor/Pages/Add.razor create mode 100644 TP Blazor/Pages/Add.razor.cs create mode 100644 TP Blazor/wwwroot/images/default.png 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 0000000000000000000000000000000000000000..a7446c9e8a8c755f1e21faf389634136d44fed6d GIT binary patch literal 2267 zcmeHIXBIq!$_ocGH~zGZI(lvb1m006)n z*5;1;HEW*%QWE<)?4{2);XtUPl_>z%dun#Sk$ecXg8~56=`uSWhX4Qxz%5&6i`?AY zyu7@(Z{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