diff --git a/myBlazorApp/myBlazorApp/Components/MyInventory.razor b/myBlazorApp/myBlazorApp/Components/MyInventory.razor
index 908d22f..10285f0 100644
--- a/myBlazorApp/myBlazorApp/Components/MyInventory.razor
+++ b/myBlazorApp/myBlazorApp/Components/MyInventory.razor
@@ -19,5 +19,4 @@
-
-
+
\ No newline at end of file
diff --git a/myBlazorApp/myBlazorApp/Pages/Inventory.razor b/myBlazorApp/myBlazorApp/Pages/Inventory.razor
index 829b2cf..eb4a413 100644
--- a/myBlazorApp/myBlazorApp/Pages/Inventory.razor
+++ b/myBlazorApp/myBlazorApp/Pages/Inventory.razor
@@ -1,51 +1,48 @@
-@page "/inventory"
-@using myBlazorApp.Components
+@page "/inventory"
+@using myBlazorApp.Components
@using System.Globalization
-@using myBlazorApp.Models;
-
-
-
-
-
-
-
-
-
-
-
List of Items
- @*SearchBar*@
-
-
-
-
-
-
+@using myBlazorApp.Models;
+
+
+
+
+
+
+
+
+
+
+
+
+
List of items
@*SearchBar*@
-
-
-
-
-
+
+
+
+
+
- @if (!string.IsNullOrWhiteSpace(context.ImageBase64))
- {
-
- }
- else
- {
-
- }
-
-
-
-
+
+ @if (!string.IsNullOrWhiteSpace(context.ImageBase64))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
+
+
\ No newline at end of file
diff --git a/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs
index 39e3a98..faf90a5 100644
--- a/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs
+++ b/myBlazorApp/myBlazorApp/Pages/Inventory.razor.cs
@@ -1,75 +1,75 @@
-using System;
-using Blazored.Modal;
-using Blazored.Modal.Services;
-using Blazorise.DataGrid;
-using Microsoft.AspNetCore.Components;
-using Microsoft.Extensions.Localization;
+using System;
+using Blazored.Modal;
+using Blazored.Modal.Services;
+using Blazorise.DataGrid;
+using Microsoft.AspNetCore.Components;
+using Microsoft.Extensions.Localization;
using myBlazorApp.Factories;
-using myBlazorApp.Modals;
-using myBlazorApp.Models;
-using myBlazorApp.Services;
-
-namespace myBlazorApp.Pages
-{
- public partial class Inventory
- {
-
- [Parameter]
- public int Id { get; set; }
-
- private ItemModel itemModel = new()
- {
- EnchantCategories = new List
(),
- RepairWith = new List()
- };
-
- private List- items = new List
- ();
-
- private int totalItem;
-
- [Inject]
- public IDataService DataService { get; set; }
-
- [Inject]
- public IWebHostEnvironment WebHostEnvironment { get; set; }
-
- [Inject]
- public NavigationManager NavigationManager { get; set; }
-
- [CascadingParameter]
- public IModalService Modal { get; set; }
-
- private async Task OnReadData(DataGridReadDataEventArgs
- e)
- {
- if (e.CancellationToken.IsCancellationRequested)
- {
- return;
- }
-
- if (!e.CancellationToken.IsCancellationRequested)
- {
- items = await DataService.List(e.Page, e.PageSize);
- totalItem = await DataService.Count();
- }
- }
-
- private async void OnDelete(int id)
- {
- var parameters = new ModalParameters();
- parameters.Add(nameof(Item.Id), id);
-
- var modal = Modal.Show("Delete Confirmation", parameters);
- var result = await modal.Result;
-
- if (result.Cancelled)
- {
- return;
- }
-
- await DataService.Delete(id);
-
- // Reload the page
- NavigationManager.NavigateTo("list", true);
+using myBlazorApp.Modals;
+using myBlazorApp.Models;
+using myBlazorApp.Services;
+
+namespace myBlazorApp.Pages
+{
+ public partial class Inventory
+ {
+
+ [Parameter]
+ public int Id { get; set; }
+
+ private ItemModel itemModel = new()
+ {
+ EnchantCategories = new List(),
+ RepairWith = new List()
+ };
+
+ private List
- items = new List
- ();
+
+ private int totalItem;
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
+ [CascadingParameter]
+ public IModalService Modal { get; set; }
+
+ private async Task OnReadData(DataGridReadDataEventArgs
- e)
+ {
+ if (e.CancellationToken.IsCancellationRequested)
+ {
+ return;
+ }
+
+ if (!e.CancellationToken.IsCancellationRequested)
+ {
+ items = await DataService.List(e.Page, e.PageSize);
+ totalItem = await DataService.Count();
+ }
+ }
+
+ private async void OnDelete(int id)
+ {
+ var parameters = new ModalParameters();
+ parameters.Add(nameof(Item.Id), id);
+
+ var modal = Modal.Show("Delete Confirmation", parameters);
+ var result = await modal.Result;
+
+ if (result.Cancelled)
+ {
+ return;
+ }
+
+ await DataService.Delete(id);
+
+ // Reload the page
+ NavigationManager.NavigateTo("list", true);
}
protected override async Task OnInitializedAsync()
@@ -86,7 +86,7 @@ namespace myBlazorApp.Pages
// Set the model with the item
itemModel = ItemFactory.ToModel(item, fileContent);
}
-
- }
-}
-
+
+ }
+}
+
diff --git a/myBlazorApp/myBlazorApp/Services/DataApiService.cs b/myBlazorApp/myBlazorApp/Services/DataApiService.cs
index 7027759..10a24aa 100644
--- a/myBlazorApp/myBlazorApp/Services/DataApiService.cs
+++ b/myBlazorApp/myBlazorApp/Services/DataApiService.cs
@@ -6,11 +6,12 @@ using static System.Net.WebRequestMethods;
namespace myBlazorApp.Services
{
- public class DataApiService : IDataService
- {
+ public class DataApiService : IDataService
+ {
private readonly HttpClient _http;
- public DataApiService(HttpClient http)
+ public DataApiService(
+ HttpClient http)
{
_http = http;
}
@@ -21,40 +22,40 @@ namespace myBlazorApp.Services
var item = ItemFactory.Create(model);
// Save the data
- await _http.PostAsJsonAsync("https://localhost:8635/api/Crafting/", item);
+ await _http.PostAsJsonAsync("https://localhost:7234/api/Crafting/", item);
}
public async Task Count()
{
- return await _http.GetFromJsonAsync("https://localhost:8635/api/Crafting/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:8635/api/Crafting/?currentPage={currentPage}&pageSize={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:8635/api/Crafting/{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:8635/api/Crafting/{id}", item);
+ await _http.PutAsJsonAsync($"https://localhost:7234/api/Crafting/{id}", item);
}
public async Task Delete(int id)
{
- await _http.DeleteAsync($"https://localhost:8635/api/Crafting/{id}");
+ await _http.DeleteAsync($"https://localhost:7234/api/Crafting/{id}");
}
public async Task
> GetRecipes()
{
- return await _http.GetFromJsonAsync>("https://localhost:8635/api/Crafting/recipe");
+ return await _http.GetFromJsonAsync>("https://localhost:7234/api/Crafting/recipe");
}
}
}
diff --git a/myBlazorApp/myBlazorApp/Services/DataLocalService.cs b/myBlazorApp/myBlazorApp/Services/DataLocalService.cs
index 5c0e36f..2bbe9d9 100644
--- a/myBlazorApp/myBlazorApp/Services/DataLocalService.cs
+++ b/myBlazorApp/myBlazorApp/Services/DataLocalService.cs
@@ -1,39 +1,39 @@
- using System;
-using Blazored.LocalStorage;
-using Microsoft.AspNetCore.Components;
-using myBlazorApp.Components;
-using myBlazorApp.Factories;
-using myBlazorApp.Models;
-
-namespace myBlazorApp.Services
-{
- public class DataLocalService : IDataService
- {
- private readonly HttpClient _http;
- private readonly ILocalStorageService _localStorage;
- private readonly NavigationManager _navigationManager;
- private readonly IWebHostEnvironment _webHostEnvironment;
-
- public DataLocalService(ILocalStorageService localStorage,
- HttpClient http,
- IWebHostEnvironment webHostEnvironment,
- NavigationManager navigationManager)
- {
- _localStorage = localStorage;
- _http = http;
- _webHostEnvironment = webHostEnvironment;
- _navigationManager = navigationManager;
- }
-
- public async Task Add(ItemModel model)
- {
- // Get the current data
- var currentData = await _localStorage.GetItemAsync>("data");
-
- //Simulate the Id
- model.Id = currentData.Max(s => s.Id) + 1;
-
- /// Add the item to the current data
+ using System;
+using Blazored.LocalStorage;
+using Microsoft.AspNetCore.Components;
+using myBlazorApp.Components;
+using myBlazorApp.Factories;
+using myBlazorApp.Models;
+
+namespace myBlazorApp.Services
+{
+ public class DataLocalService : IDataService
+ {
+ private readonly HttpClient _http;
+ private readonly ILocalStorageService _localStorage;
+ private readonly NavigationManager _navigationManager;
+ private readonly IWebHostEnvironment _webHostEnvironment;
+
+ public DataLocalService(ILocalStorageService localStorage,
+ HttpClient http,
+ IWebHostEnvironment webHostEnvironment,
+ NavigationManager navigationManager)
+ {
+ _localStorage = localStorage;
+ _http = http;
+ _webHostEnvironment = webHostEnvironment;
+ _navigationManager = navigationManager;
+ }
+
+ public async Task Add(ItemModel model)
+ {
+ // Get the current data
+ var currentData = await _localStorage.GetItemAsync>("data");
+
+ //Simulate the Id
+ model.Id = currentData.Max(s => s.Id) + 1;
+
+ /// Add the item to the current data
currentData.Add(ItemFactory.Create(model));
// Save the image
@@ -49,62 +49,62 @@ namespace myBlazorApp.Services
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
// Write the file content
- await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
-
-
- // Save the data
- await _localStorage.SetItemAsync("data", currentData);
- }
-
- public async Task Count()
- {
- return (await _localStorage.GetItemAsync- ("data")).Length;
- }
-
- public async Task
> List(int currentPage, int pageSize)
- {
- // Load data from local storage
- var currentData = await _localStorage.GetItemAsync- ("data");
- // Check if data exist in the local storage
- if (currentData == null)
- {
- // this code add in the local storage the fake data
- var originalData = await _http.GetFromJsonAsync
- ($"{_navigationManager.BaseUri}fake-data.json");
- await _localStorage.SetItemAsync("data", originalData);
- }
-
- return (await _localStorage.GetItemAsync
- ("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
- }
-
- public async Task
- GetById(int id)
- {
- // 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}");
- }
-
- return item;
- }
-
- public async Task Update(int id, ItemModel model)
- {
- // 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}");
+ await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
+
+
+ // Save the data
+ await _localStorage.SetItemAsync("data", currentData);
+ }
+
+ public async Task Count()
+ {
+ return (await _localStorage.GetItemAsync- ("data")).Length;
+ }
+
+ public async Task
> List(int currentPage, int pageSize)
+ {
+ // Load data from local storage
+ var currentData = await _localStorage.GetItemAsync- ("data");
+ // Check if data exist in the local storage
+ if (currentData == null)
+ {
+ // this code add in the local storage the fake data
+ var originalData = await _http.GetFromJsonAsync
- ($"{_navigationManager.BaseUri}fake-data.json");
+ await _localStorage.SetItemAsync("data", originalData);
+ }
+
+ return (await _localStorage.GetItemAsync
- ("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
+ }
+
+ public async Task
- GetById(int id)
+ {
+ // 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}");
+ }
+
+ return item;
+ }
+
+ public async Task Update(int id, ItemModel model)
+ {
+ // 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}");
}
// Save the image
@@ -131,24 +131,24 @@ namespace myBlazorApp.Services
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);
-
- // Save the data
- await _localStorage.SetItemAsync("data", currentData);
- }
-
- public async Task Delete(int id)
- {
- // Get the current data
- var currentData = await _localStorage.GetItemAsync>("data");
-
- // Get the item int the list
- var item = currentData.FirstOrDefault(w => w.Id == id);
-
- // Delete item in
+ await File.WriteAllBytesAsync(fileName.FullName, model.ImageContent);
+
+ // Modify the content of the item
+ ItemFactory.Update(item, model);
+
+ // Save the data
+ await _localStorage.SetItemAsync("data", currentData);
+ }
+
+ public async Task Delete(int id)
+ {
+ // Get the current data
+ var currentData = await _localStorage.GetItemAsync>("data");
+
+ // Get the item int the list
+ var item = currentData.FirstOrDefault(w => w.Id == id);
+
+ // Delete item in
currentData.Remove(item);
// Delete the image
@@ -158,29 +158,29 @@ namespace myBlazorApp.Services
if (fileName.Exists)
{
File.Delete(fileName.FullName);
- }
-
- // Save the data
- await _localStorage.SetItemAsync("data", currentData);
- }
-
- public Task> GetRecipes()
- {
- var items = new List
- {
- new CraftingRecipe
- {
- Give = new Item { DisplayName = "Diamond", Name = "diamond" },
- Have = new List>
- {
- new List { "dirt", "dirt", "dirt" },
- new List { "dirt", null, "dirt" },
- new List { "dirt", "dirt", "dirt" }
- }
- }
- };
-
- return Task.FromResult(items);
- }
- }
-}
+ }
+
+ // Save the data
+ await _localStorage.SetItemAsync("data", currentData);
+ }
+
+ public Task> GetRecipes()
+ {
+ var items = new List
+ {
+ new CraftingRecipe
+ {
+ Give = new Item { DisplayName = "Diamond", Name = "diamond" },
+ Have = new List>
+ {
+ new List { "dirt", "dirt", "dirt" },
+ new List { "dirt", null, "dirt" },
+ new List { "dirt", "dirt", "dirt" }
+ }
+ }
+ };
+
+ return Task.FromResult(items);
+ }
+ }
+}