From 8a1d6cea093142789333a80479e57103bedba812 Mon Sep 17 00:00:00 2001 From: Louis DUFOUR Date: Fri, 30 Dec 2022 13:59:37 +0100 Subject: [PATCH] Update drag --- .../Components/InventoryItem.razor | 2 +- .../Components/InventoryItem.razor.css | 7 ++ ValblazeProject/Pages/Inventaire.razor | 19 +--- ValblazeProject/Pages/Inventaire.razor.cs | 28 ++--- ValblazeProject/Pages/Inventaire.razor.css | 14 --- ValblazeProject/Pages/Inventaire.razor.js | 2 +- .../Pages/Services/DataApiService.cs | 29 ++--- .../Pages/Services/DataLocalService.cs | 101 ++++-------------- .../Pages/Services/IDataService.cs | 11 +- 9 files changed, 61 insertions(+), 152 deletions(-) diff --git a/ValblazeProject/Components/InventoryItem.razor b/ValblazeProject/Components/InventoryItem.razor index a600c90..d11a60a 100644 --- a/ValblazeProject/Components/InventoryItem.razor +++ b/ValblazeProject/Components/InventoryItem.razor @@ -9,6 +9,6 @@ @if (Item != null) { - @Item.DisplayName + @Item.DisplayName } \ No newline at end of file diff --git a/ValblazeProject/Components/InventoryItem.razor.css b/ValblazeProject/Components/InventoryItem.razor.css index 4e20b01..aa45fc4 100644 --- a/ValblazeProject/Components/InventoryItem.razor.css +++ b/ValblazeProject/Components/InventoryItem.razor.css @@ -6,3 +6,10 @@ border: 1px solid; overflow: hidden; } + +.imageList { + min-width: 50px; + max-width: 50px; + height: 50px; + margin: auto +} \ No newline at end of file diff --git a/ValblazeProject/Pages/Inventaire.razor b/ValblazeProject/Pages/Inventaire.razor index a2a5045..2e61129 100644 --- a/ValblazeProject/Pages/Inventaire.razor +++ b/ValblazeProject/Pages/Inventaire.razor @@ -6,6 +6,7 @@ +

@Localizer["key1"]

@@ -43,20 +44,7 @@ @if (!string.IsNullOrWhiteSpace(context.ImageBase64)) { -
- - @if (context != null) - { - @context.DisplayName - } -
+ } else { @@ -67,4 +55,5 @@
-
\ No newline at end of file + +
\ No newline at end of file diff --git a/ValblazeProject/Pages/Inventaire.razor.cs b/ValblazeProject/Pages/Inventaire.razor.cs index 306b89f..0cf59f8 100644 --- a/ValblazeProject/Pages/Inventaire.razor.cs +++ b/ValblazeProject/Pages/Inventaire.razor.cs @@ -36,6 +36,8 @@ namespace ValblazeProject.Pages private List items; private int totalItem; + private List invents; + private DataGrid dataGrid; private string _searchText; private int totalSizeByPage = 5; @@ -59,7 +61,7 @@ namespace ValblazeProject.Pages } // Drag - protected override async Task OnAfterRenderAsync(bool firstRender) +/* protected override async Task OnAfterRenderAsync(bool firstRender) { base.OnAfterRenderAsync(firstRender); @@ -68,28 +70,10 @@ namespace ValblazeProject.Pages return; } - StateHasChanged(); - } - - private CraftingItem Drag; + //invents = await DataService.List(0, await DataService.Count()); - public void OnDragEnter() - { - Drag.OnDragEnter(); - } - public void OnDragStart() - { - Drag.OnDragStart(); - } - public void OnDrop() - { - Drag.OnDrop(); - } - public void OnDragLeave() - { - Drag.OnDragLeave(); - } - + StateHasChanged(); + }*/ /******************* Attribut modifier *******************/ private string search diff --git a/ValblazeProject/Pages/Inventaire.razor.css b/ValblazeProject/Pages/Inventaire.razor.css index f787af5..8da2b69 100644 --- a/ValblazeProject/Pages/Inventaire.razor.css +++ b/ValblazeProject/Pages/Inventaire.razor.css @@ -38,18 +38,4 @@ margin-right: 20px; } -.item { - display: flex; - justify-content: center; - width: 64px; - height: 64px; - border: 1px solid; - overflow: hidden; -} -.imageList { - min-width: 50px; - max-width: 50px; - height: 50px; - margin: auto -} \ No newline at end of file diff --git a/ValblazeProject/Pages/Inventaire.razor.js b/ValblazeProject/Pages/Inventaire.razor.js index 8fdb58e..70afada 100644 --- a/ValblazeProject/Pages/Inventaire.razor.js +++ b/ValblazeProject/Pages/Inventaire.razor.js @@ -1,4 +1,4 @@ -window.Crafting = +window.Inventaire = { AddActions: function (data) { diff --git a/ValblazeProject/Pages/Services/DataApiService.cs b/ValblazeProject/Pages/Services/DataApiService.cs index c85e0f9..637536c 100644 --- a/ValblazeProject/Pages/Services/DataApiService.cs +++ b/ValblazeProject/Pages/Services/DataApiService.cs @@ -63,28 +63,31 @@ namespace ValblazeProject.Services return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe"); } - /************ Inventory ************ - public async Task supprInventory() + /************ Inventory ************/ + public async Task SupprInventory(Inventory item) { - await _http.DeleteAsync("https://localhost:7234/api/Inventory"); + HttpRequestMessage request = new HttpRequestMessage + { + Content = JsonContent.Create(item), + Method = HttpMethod.Delete, + RequestUri = new Uri("https://localhost:7234/api/Inventory") + }; + await _http.SendAsync(request); } - public async Task getInventory() + public async Task> GetInventory() { - return await _http.GetFromJsonAsync("https://localhost:7234/api/Inventory"); + return await _http.GetFromJsonAsync>("https://localhost:7234/api/Inventory"); } - public async Task putInventory() + public async Task PutInventory(Inventory item) { - await _http.PutAsJsonAsync($"https://localhost:7234/api/Inventory"); + await _http.PutAsJsonAsync($"https://localhost:7234/api/Inventory", item); } - public async Task postInventory() + public async Task PostInventory(Inventory item) { - // Get the inventory - var inventory = ItemFactory.Create(item); - // Save the data - await _http.PostAsJsonAsync("https://localhost:7234/api/Inventory", inventory); - }*/ + await _http.PostAsJsonAsync("https://localhost:7234/api/Inventory", item); + } } } diff --git a/ValblazeProject/Pages/Services/DataLocalService.cs b/ValblazeProject/Pages/Services/DataLocalService.cs index 1ca8e7f..ad6ece8 100644 --- a/ValblazeProject/Pages/Services/DataLocalService.cs +++ b/ValblazeProject/Pages/Services/DataLocalService.cs @@ -201,123 +201,62 @@ namespace ValblazeProject.Services return (await _localStorage.GetItemAsync("data")).ToList(); } - /************************ Inventory ************************ - public async Task supprInventory() + /************************ Inventory ************************/ + public async Task SupprInventory(Inventory itemSearch) { // Get the current data - var currentData = await _localStorage.GetItemAsync("data"); + var currentData = await _localStorage.GetItemAsync>("KeyInvent"); // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); + var item = currentData.FirstOrDefault(w => w.position == itemSearch.position); // Delete item in currentData.Remove(item); - // Delete the image - var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); - var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); - - if (fileName.Exists) - { - File.Delete(fileName.FullName); - } - // Save the data await _localStorage.SetItemAsync("data", currentData); } - public async Task getInventory() + public async Task> GetInventory() { // Get the current data - var currentData = await _localStorage.GetItemAsync("data"); - - // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); - - // Check if item exist - if (item == null) - { - throw new Exception($"Unable to found the item with ID: {id}"); - } + var currentData = await _localStorage.GetItemAsync>("KeyInvent"); - return item; + return currentData; } - public async Task putInventory() + public async Task PutInventory(Inventory invent) { // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); + var currentData = await _localStorage.GetItemAsync>("KeyInvent"); // Get the item int the list - var item = currentData.FirstOrDefault(w => w.Id == id); + var item = currentData.FirstOrDefault(w => w.position == invent.position); // Check if item exist if (item == null) { - throw new Exception($"Unable to found the item with ID: {id}"); - } - - // Save the image - var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); - - // Check if the folder "images" exist - if (!imagePathInfo.Exists) - { - imagePathInfo.Create(); - } - - // Delete the previous image - if (item.Name != model.Name) - { - var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); - - if (oldFileName.Exists) - { - File.Delete(oldFileName.FullName); - } + throw new Exception($"Unable to found the item with ID: {item.position}"); } - // Determine the image name - var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png"); - - // Write the file content - await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent); - - // Modify the content of the item - ItemFactory.Update(item, model); + item.position = invent.position; + item.numberItem = invent.numberItem; + item.itemName = invent.itemName; // Save the data - await _localStorage.SetItemAsync("data", currentData); + await _localStorage.SetItemAsync("KeyInvent", currentData); } - public async Task postInventory() + public async Task PostInventory(Inventory invent) { // Get the current data - var currentData = await _localStorage.GetItemAsync>("data"); - - // Simulate the Id - model.Id = currentData.Max(s => s.Id) + 1; + var currentData = await _localStorage.GetItemAsync>("KeyInvent"); // Add the item to the current data - currentData.Add(ItemFactory.Create(model)); - - // 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}/{model.Name}.png"); - - // Write the file content - await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent); + currentData.Add(invent); // Save the data - await _localStorage.SetItemAsync("data", currentData); - }*/ + await _localStorage.SetItemAsync("KeyInvent", currentData); + } } } diff --git a/ValblazeProject/Pages/Services/IDataService.cs b/ValblazeProject/Pages/Services/IDataService.cs index 42a1291..1aac0ee 100644 --- a/ValblazeProject/Pages/Services/IDataService.cs +++ b/ValblazeProject/Pages/Services/IDataService.cs @@ -15,10 +15,11 @@ namespace ValblazeProject.Services Task Delete(int id); Task> GetRecipes(); - /* Inventory - Task getInventory(); - Task supprInventory(); - Task postInventory(); - Task putInventory();*/ + // Inventory + Task> GetInventory(); + Task SupprInventory(Inventory item); + Task PutInventory(Inventory item); + Task PostInventory(Inventory item); + } }