diff --git a/src/CraftSharp/Components/CraftingItem.razor b/src/CraftSharp/Components/CraftingItem.razor
index db4ca36..450dfc5 100644
--- a/src/CraftSharp/Components/CraftingItem.razor
+++ b/src/CraftSharp/Components/CraftingItem.razor
@@ -1,4 +1,6 @@
-
+ @if ((Items?.Count ?? 0) != 0)
+ {
+ @foreach (var item in Items)
+ {
+ @ShowTemplate(item);
+ }
+ }
+
\ No newline at end of file
diff --git a/src/CraftSharp/Components/ShowItems.razor.cs b/src/CraftSharp/Components/ShowItems.razor.cs
new file mode 100644
index 0000000..5ac9e39
--- /dev/null
+++ b/src/CraftSharp/Components/ShowItems.razor.cs
@@ -0,0 +1,13 @@
+using Microsoft.AspNetCore.Components;
+
+namespace CraftSharp.Components
+{
+ public partial class ShowItems
+ {
+ [Parameter]
+ public List Items { get; set; }
+
+ [Parameter]
+ public RenderFragment ShowTemplate { get; set; }
+ }
+}
diff --git a/src/CraftSharp/CraftSharp.csproj b/src/CraftSharp/CraftSharp.csproj
index 6fa0141..cfd494e 100644
--- a/src/CraftSharp/CraftSharp.csproj
+++ b/src/CraftSharp/CraftSharp.csproj
@@ -1,30 +1,24 @@
-
-
-
- net6.0
- enable
- enable
- 41eb41f8-57fb-408a-baab-7328f468e749
- Windows
- .
-
-
+
+
+
+ net6.0
+ enable
+ enable
+ 41eb41f8-57fb-408a-baab-7328f468e749
+ Windows
+ .
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
diff --git a/src/CraftSharp/Factories/ItemFactory.cs b/src/CraftSharp/Factories/ItemFactory.cs
new file mode 100644
index 0000000..e0e91fd
--- /dev/null
+++ b/src/CraftSharp/Factories/ItemFactory.cs
@@ -0,0 +1,55 @@
+using CraftSharp.Models;
+
+namespace CraftSharp.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,
+ ImageBase64 = string.IsNullOrWhiteSpace(item.ImageBase64) ? Convert.ToBase64String(imageContent) : item.ImageBase64,
+ Rarity = item.Rarity
+ };
+ }
+
+ 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,
+ ImageBase64 = Convert.ToBase64String(model.ImageContent),
+ Rarity = model.Rarity
+ };
+ }
+
+ 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;
+ item.ImageBase64 = Convert.ToBase64String(model.ImageContent);
+ item.Rarity = model.Rarity;
+
+ }
+}
+}
diff --git a/src/CraftSharp/Models/Item.cs b/src/CraftSharp/Models/Item.cs
index dd642cd..eaf12d8 100644
--- a/src/CraftSharp/Models/Item.cs
+++ b/src/CraftSharp/Models/Item.cs
@@ -3,9 +3,16 @@
public class Item
{
public int Id { get; set; }
+ public string DisplayName { get; set; }
public string Name { get; set; }
public int StackSize { get; set; }
+ public int MaxDurability { get; set; }
+ public List EnchantCategories { get; set; }
+ public List RepairWith { get; set; }
+ public DateTime CreatedDate { get; set; }
+ public DateTime? UpdatedDate { get; set; }
public string ImageBase64 { get; set; }
+
public Rarities Rarity { get; set; }
}
}
diff --git a/src/CraftSharp/Models/ItemModel.cs b/src/CraftSharp/Models/ItemModel.cs
index 1bfd9c2..a778e4a 100644
--- a/src/CraftSharp/Models/ItemModel.cs
+++ b/src/CraftSharp/Models/ItemModel.cs
@@ -35,6 +35,8 @@ namespace CraftSharp.Models
public byte[] ImageContent { get; set; }
public string ImageBase64 { get; set; }
-
+
+ [Required]
+ public Rarities Rarity { get; set; }
}
}
diff --git a/src/CraftSharp/Program.cs b/src/CraftSharp/Program.cs
index 1390d26..5ced326 100644
--- a/src/CraftSharp/Program.cs
+++ b/src/CraftSharp/Program.cs
@@ -1,4 +1,5 @@
using CraftSharp.Data;
+using CraftSharp.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Localization;
@@ -18,6 +19,10 @@ builder.Services.AddControllers();
// Add the localization to the app and specify the resources path
builder.Services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
+builder.Services.AddHttpClient();
+
+builder.Services.AddScoped();
+
// Configure the localtization
builder.Services.Configure(options =>
{
diff --git a/src/CraftSharp/Services/DataApiService.cs b/src/CraftSharp/Services/DataApiService.cs
new file mode 100644
index 0000000..0a8d477
--- /dev/null
+++ b/src/CraftSharp/Services/DataApiService.cs
@@ -0,0 +1,59 @@
+using CraftSharp.Components;
+using CraftSharp.Factories;
+using CraftSharp.Models;
+
+namespace CraftSharp.Services
+{
+ public class DataApiService : IDataService
+ {
+ private readonly HttpClient _http;
+
+ public DataApiService(
+ HttpClient http)
+ {
+ _http = http;
+ }
+
+ public async Task Add(ItemModel model)
+ {
+ // Get the item
+ var item = ItemFactory.Create(model);
+
+ // Save the data
+ await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item);
+ }
+
+ public async Task Count()
+ {
+ return await _http.GetFromJsonAsync("https://localhost:7234/api/Crafting/count");
+ }
+
+ public async Task> List(int currentPage, int pageSize)
+ {
+ return await _http.GetFromJsonAsync>($"https://localhost:7234/api/Crafting/?currentPage={currentPage}&pageSize={pageSize}");
+ }
+
+ public async Task- GetById(int id)
+ {
+ return await _http.GetFromJsonAsync
- ($"https://localhost:7234/api/Crafting/{id}");
+ }
+
+ public async Task Update(int id, ItemModel model)
+ {
+ // Get the item
+ var item = ItemFactory.Create(model);
+
+ await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item);
+ }
+
+ public async Task Delete(int id)
+ {
+ await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}");
+ }
+
+ public async Task
> GetRecipes()
+ {
+ return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe");
+ }
+ }
+}
diff --git a/src/CraftSharp/Services/IDataService.cs b/src/CraftSharp/Services/IDataService.cs
index 5956a53..c5a515c 100644
--- a/src/CraftSharp/Services/IDataService.cs
+++ b/src/CraftSharp/Services/IDataService.cs
@@ -1,7 +1,7 @@
using CraftSharp.Components;
using CraftSharp.Models;
-namespace Blazor.Services
+namespace CraftSharp.Services
{
public interface IDataService
{