+
+
+
\ No newline at end of file
diff --git a/BlazorApp1/Pages/Add.razor.cs b/BlazorApp1/Pages/Add.razor.cs
new file mode 100644
index 0000000..68c51af
--- /dev/null
+++ b/BlazorApp1/Pages/Add.razor.cs
@@ -0,0 +1,125 @@
+using BlazorApp1.Models;
+using Blazored.LocalStorage;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
+
+namespace BlazorApp1.Pages
+{
+ public partial class Add
+ {
+ [Inject]
+ public ILocalStorageService LocalStorage { get; set; }
+
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ ///
+ /// The default enchant categories.
+ ///
+ private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" };
+
+ ///
+ /// The default repair with.
+ ///
+ private List repairWith = new List() { "oak_planks", "spruce_planks", "birch_planks", "jungle_planks", "acacia_planks", "dark_oak_planks", "crimson_planks", "warped_planks" };
+
+ ///
+ /// The current item model
+ ///
+ private ItemModel itemModel = new()
+ {
+ EnchantCategories = new List(),
+ RepairWith = new List()
+ };
+
+ private async void HandleValidSubmit()
+ {
+ // Get the current data
+ var currentData = await LocalStorage.GetItemAsync>("data");
+
+ // Simulate the Id
+ itemModel.Id = currentData.Max(s => s.Id) + 1;
+
+ // Add the item to the current data
+ 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
+ });
+
+ // 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}/{itemModel.Name}.png");
+
+ // Write the file content
+ await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent);
+
+ // Save the data
+ await LocalStorage.SetItemAsync("data", currentData);
+ NavigationManager.NavigateTo("list");
+ }
+
+ private async Task LoadImage(InputFileChangeEventArgs e)
+ {
+ // Set the content of the image to the model
+ 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/BlazorApp1/Pages/BlazorRoute.razor b/BlazorApp1/Pages/BlazorRoute.razor
new file mode 100644
index 0000000..40307dd
--- /dev/null
+++ b/BlazorApp1/Pages/BlazorRoute.razor
@@ -0,0 +1,4 @@
+@page "/BlazorRoute"
+@page "/DifferentBlazorRoute"
+
+
Blazor routing
\ No newline at end of file
diff --git a/BlazorApp1/Pages/List.razor b/BlazorApp1/Pages/List.razor
index 7e0a6db..5ec4d95 100644
--- a/BlazorApp1/Pages/List.razor
+++ b/BlazorApp1/Pages/List.razor
@@ -3,26 +3,44 @@
List
-
+
+ Ajouter
+
+
+
+
-
-
-
-
-
+
+
+
+ @if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{context.Name}.png"))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
+
+
+
- @(string.Join(", ", ((Items)context).EnchantCategories))
+ @(string.Join(", ", ((Item)context).EnchantCategories))
-
+
- @(string.Join(", ", ((Items)context).RepairWith))
+ @(string.Join(", ", ((Item)context).RepairWith))
-
+
\ No newline at end of file
diff --git a/BlazorApp1/Pages/list.razor.cs b/BlazorApp1/Pages/list.razor.cs
index 030589e..9d9a230 100644
--- a/BlazorApp1/Pages/list.razor.cs
+++ b/BlazorApp1/Pages/list.razor.cs
@@ -1,4 +1,5 @@
using BlazorApp1.Models;
+using Blazored.LocalStorage;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
@@ -6,17 +7,42 @@ namespace BlazorApp1.Pages
{
public partial class List
{
- private List items;
+ private List items;
private int totalItem;
[Inject]
public HttpClient Http { get; set; }
+ [Inject]
+ public ILocalStorageService LocalStorage { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
[Inject]
public NavigationManager NavigationManager { get; set; }
- private async Task OnReadData(DataGridReadDataEventArgs e)
+ protected override async Task OnAfterRenderAsync(bool firstRender)
+ {
+ // Do not treat this action if is not the first render
+ if (!firstRender)
+ {
+ return;
+ }
+
+ 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 (we load the data sync for initialize the data before load the OnReadData method)
+ var originalData = Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json").Result;
+ await LocalStorage.SetItemAsync("data", originalData);
+ }
+ }
+
+ private async Task OnReadData(DataGridReadDataEventArgs e)
{
if (e.CancellationToken.IsCancellationRequested)
{
@@ -24,13 +50,13 @@ namespace BlazorApp1.Pages
}
// When you use a real API, we use this follow code
- //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
- var response = (await Http.GetFromJsonAsync($"{NavigationManager.BaseUri}fake-data.json")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
+ //var response = await Http.GetJsonAsync( $"http://my-api/api/data?page={e.Page}&pageSize={e.PageSize}" );
+ var response = (await LocalStorage.GetItemAsync("data")).Skip((e.Page - 1) * e.PageSize).Take(e.PageSize).ToList();
if (!e.CancellationToken.IsCancellationRequested)
{
- totalItem = (await Http.GetFromJsonAsync>($"{NavigationManager.BaseUri}fake-data.json")).Count;
- items = new List(response); // an actual data for the current page
+ totalItem = (await LocalStorage.GetItemAsync>("data")).Count;
+ items = new List(response); // an actual data for the current page
}
}
}
diff --git a/BlazorApp1/Program.cs b/BlazorApp1/Program.cs
index daf28f7..7f683e4 100644
--- a/BlazorApp1/Program.cs
+++ b/BlazorApp1/Program.cs
@@ -1,4 +1,5 @@
using BlazorApp1.Data;
+using Blazored.LocalStorage;
using Blazorise;
using Blazorise.Bootstrap;
using Blazorise.Icons.FontAwesome;
@@ -16,8 +17,9 @@ builder.Services
.AddBlazorise()
.AddBootstrapProviders()
.AddFontAwesomeIcons();
+builder.Services.AddBlazoredLocalStorage();
-var app = builder.Build();
+var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
diff --git a/BlazorApp1/_Imports.razor b/BlazorApp1/_Imports.razor
index 01cb17b..6ccf59e 100644
--- a/BlazorApp1/_Imports.razor
+++ b/BlazorApp1/_Imports.razor
@@ -8,4 +8,4 @@
@using Microsoft.JSInterop
@using BlazorApp1
@using BlazorApp1.Shared
-@using Blazorise.DataGrid
+@using Blazorise.DataGrid
\ No newline at end of file
diff --git a/BlazorApp1/wwwroot/images/default.png b/BlazorApp1/wwwroot/images/default.png
new file mode 100644
index 0000000000000000000000000000000000000000..756dc18d3c81ecff1c1d68993a5c93e887277868
GIT binary patch
literal 3524
zcmV;#4LkCQP)A{NJvOTL_|SBK}SbNK0ZD}Lqp%+-^|R+^z`)5(9lj!PUq+6e0+R%c6PF|
zvTtv1US3{PQ&aKr@nvOYyu7^D*4B@YkH*HvX=!P#t*tjVH;0FZp`oFZlar*Rq=A8f
znwpwfSy|h6n>PRe4Gl>|K~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