diff --git a/ValblazeProject/Factories/ItemFactory.cs b/ValblazeProject/Factories/ItemFactory.cs new file mode 100644 index 0000000..143eeb3 --- /dev/null +++ b/ValblazeProject/Factories/ItemFactory.cs @@ -0,0 +1,48 @@ +using ValblazeProject.Models; + +namespace ValblazeProject.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/ValblazeProject/Pages/Edit.razor.cs b/ValblazeProject/Pages/Edit.razor.cs index 5d3a739..3389690 100644 --- a/ValblazeProject/Pages/Edit.razor.cs +++ b/ValblazeProject/Pages/Edit.razor.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; +using ValblazeProject.Factories; using ValblazeProject.Models; using ValblazeProject.Services; @@ -50,17 +51,7 @@ namespace ValblazeProject.Pages } // 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() diff --git a/ValblazeProject/Services/DataLocalService.cs b/ValblazeProject/Services/DataLocalService.cs index b99eff6..42a923d 100644 --- a/ValblazeProject/Services/DataLocalService.cs +++ b/ValblazeProject/Services/DataLocalService.cs @@ -1,5 +1,6 @@ using Blazored.LocalStorage; using Microsoft.AspNetCore.Components; +using ValblazeProject.Factories; using ValblazeProject.Models; namespace ValblazeProject.Services @@ -32,17 +33,7 @@ namespace ValblazeProject.Services model.Id = currentData.Max(s => s.Id) + 1; // Add the item to the current data - currentData.Add(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 - }); + currentData.Add(ItemFactory.Create(model)); // Save the image var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); @@ -142,13 +133,7 @@ namespace ValblazeProject.Services await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent); // Modify the content of the item - 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; + ItemFactory.Update(item, model); // Save the data await _localStorage.SetItemAsync("data", currentData); diff --git a/ValblazeProject/wwwroot/images/mind.png b/ValblazeProject/wwwroot/images/mind.png new file mode 100644 index 0000000..f5d5ef9 Binary files /dev/null and b/ValblazeProject/wwwroot/images/mind.png differ diff --git a/ValblazeProject/wwwroot/images/twiis.png b/ValblazeProject/wwwroot/images/twiis.png new file mode 100644 index 0000000..87d9e83 Binary files /dev/null and b/ValblazeProject/wwwroot/images/twiis.png differ diff --git a/ValblazeProject/wwwroot/images/zilch.png b/ValblazeProject/wwwroot/images/zilch.png new file mode 100644 index 0000000..ab4bbdc Binary files /dev/null and b/ValblazeProject/wwwroot/images/zilch.png differ