From b1cc8d178c1f88c88b0829f434f03794e1e7ad70 Mon Sep 17 00:00:00 2001
From: Thomas Chazot
Date: Tue, 15 Nov 2022 08:55:49 +0100
Subject: [PATCH] =?UTF-8?q?Avanc=C3=A9e=20jusqu=E2=80=99=C3=A0=20l?=
=?UTF-8?q?=E2=80=99api=20mais=20probl=C3=A8me=20sur=20la=20partie=20using?=
=?UTF-8?q?=20component?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
BlazorApp/BlazorApp/App.razor | 18 ++--
BlazorApp/BlazorApp/BlazorApp.csproj | 25 +++++
BlazorApp/BlazorApp/Components/Card.razor | 9 ++
BlazorApp/BlazorApp/Components/Card.razor.cs | 21 ++++
BlazorApp/BlazorApp/Components/Crafting.razor | 54 ++++++++++
.../BlazorApp/Components/Crafting.razor.cs | 82 +++++++++++++++
.../BlazorApp/Components/Crafting.razor.css | 19 ++++
.../BlazorApp/Components/Crafting.razor.js | 20 ++++
.../BlazorApp/Components/CraftingAction.cs | 13 +++
.../BlazorApp/Components/CraftingItem.razor | 13 +++
.../Components/CraftingItem.razor.cs | 68 ++++++++++++
.../Components/CraftingItem.razor.css | 6 ++
.../BlazorApp/Components/CraftingRecipe.cs | 12 +++
.../Components/MyFirstChildComponent.razor | 14 +++
.../Components/MyRootComponent.razor | 16 +++
.../Components/MySecondChildComponent.razor | 14 +++
.../BlazorApp/Components/ShowItems.razor | 11 ++
.../BlazorApp/Components/ShowItems.razor.cs | 15 +++
.../Components/TestRenderFragment.razor | 7 ++
.../Controllers/CultureController.cs | 36 +++++++
BlazorApp/BlazorApp/Factories/ItemFactory.cs | 53 ++++++++++
.../BlazorApp/Modals/DeleteConfirmation.razor | 10 ++
.../Modals/DeleteConfirmation.razor.cs | 40 +++++++
BlazorApp/BlazorApp/Models/Cake.cs | 11 ++
BlazorApp/BlazorApp/Models/Item.cs | 5 +-
BlazorApp/BlazorApp/Models/ItemModel.cs | 2 +
BlazorApp/BlazorApp/Pages/Edit.razor | 79 +++++++++++++-
BlazorApp/BlazorApp/Pages/Edit.razor.cs | 99 ++++++++++++++++++
BlazorApp/BlazorApp/Pages/Index.razor | 43 +++++++-
BlazorApp/BlazorApp/Pages/Index.razor.cs | 58 ++++++++++
BlazorApp/BlazorApp/Pages/List.razor | 4 +-
BlazorApp/BlazorApp/Pages/List.razor.cs | 33 +++++-
BlazorApp/BlazorApp/Pages/Pets1.razor | 29 +++++
BlazorApp/BlazorApp/Pages/Pets2.razor | 29 +++++
BlazorApp/BlazorApp/Pages/Pets3.razor | 29 +++++
BlazorApp/BlazorApp/Pages/Pets4.razor | 29 +++++
BlazorApp/BlazorApp/Pages/_Layout.cshtml | 7 +-
BlazorApp/BlazorApp/Program.cs | 40 ++++++-
.../Resources/Pages.List.Designer.cs | 60 +++++++++++
BlazorApp/BlazorApp/Resources/Pages.List.resx | 16 +++
.../BlazorApp/Services/DataLocalService.cs | 66 ++++++++----
BlazorApp/BlazorApp/Services/IDataService.cs | 7 +-
.../BlazorApp/Shared/CultureSelector.razor | 43 ++++++++
BlazorApp/BlazorApp/Shared/MainLayout.razor | 4 +
.../BlazorApp/Shared/TableTemplate.razor | 28 +++++
BlazorApp/BlazorApp/_Imports.razor | 2 +
BlazorApp/BlazorApp/wwwroot/images/edit.png | Bin 0 -> 2267 bytes
47 files changed, 1261 insertions(+), 38 deletions(-)
create mode 100644 BlazorApp/BlazorApp/Components/Card.razor
create mode 100644 BlazorApp/BlazorApp/Components/Card.razor.cs
create mode 100644 BlazorApp/BlazorApp/Components/Crafting.razor
create mode 100644 BlazorApp/BlazorApp/Components/Crafting.razor.cs
create mode 100644 BlazorApp/BlazorApp/Components/Crafting.razor.css
create mode 100644 BlazorApp/BlazorApp/Components/Crafting.razor.js
create mode 100644 BlazorApp/BlazorApp/Components/CraftingAction.cs
create mode 100644 BlazorApp/BlazorApp/Components/CraftingItem.razor
create mode 100644 BlazorApp/BlazorApp/Components/CraftingItem.razor.cs
create mode 100644 BlazorApp/BlazorApp/Components/CraftingItem.razor.css
create mode 100644 BlazorApp/BlazorApp/Components/CraftingRecipe.cs
create mode 100644 BlazorApp/BlazorApp/Components/MyFirstChildComponent.razor
create mode 100644 BlazorApp/BlazorApp/Components/MyRootComponent.razor
create mode 100644 BlazorApp/BlazorApp/Components/MySecondChildComponent.razor
create mode 100644 BlazorApp/BlazorApp/Components/ShowItems.razor
create mode 100644 BlazorApp/BlazorApp/Components/ShowItems.razor.cs
create mode 100644 BlazorApp/BlazorApp/Components/TestRenderFragment.razor
create mode 100644 BlazorApp/BlazorApp/Controllers/CultureController.cs
create mode 100644 BlazorApp/BlazorApp/Factories/ItemFactory.cs
create mode 100644 BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor
create mode 100644 BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor.cs
create mode 100644 BlazorApp/BlazorApp/Models/Cake.cs
create mode 100644 BlazorApp/BlazorApp/Pages/Index.razor.cs
create mode 100644 BlazorApp/BlazorApp/Pages/Pets1.razor
create mode 100644 BlazorApp/BlazorApp/Pages/Pets2.razor
create mode 100644 BlazorApp/BlazorApp/Pages/Pets3.razor
create mode 100644 BlazorApp/BlazorApp/Pages/Pets4.razor
create mode 100644 BlazorApp/BlazorApp/Resources/Pages.List.Designer.cs
create mode 100644 BlazorApp/BlazorApp/Resources/Pages.List.resx
create mode 100644 BlazorApp/BlazorApp/Shared/CultureSelector.razor
create mode 100644 BlazorApp/BlazorApp/Shared/TableTemplate.razor
create mode 100644 BlazorApp/BlazorApp/wwwroot/images/edit.png
diff --git a/BlazorApp/BlazorApp/App.razor b/BlazorApp/BlazorApp/App.razor
index 60ab6f5..08b40fe 100644
--- a/BlazorApp/BlazorApp/App.razor
+++ b/BlazorApp/BlazorApp/App.razor
@@ -1,8 +1,10 @@
-
-
-
-
-
- Sorry, there's nothing at this address.
-
-
+
+
+
+
+
+
+ Sorry, there's nothing at this address.
+
+
+
diff --git a/BlazorApp/BlazorApp/BlazorApp.csproj b/BlazorApp/BlazorApp/BlazorApp.csproj
index cd54721..a00e35c 100644
--- a/BlazorApp/BlazorApp/BlazorApp.csproj
+++ b/BlazorApp/BlazorApp/BlazorApp.csproj
@@ -11,13 +11,38 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ResXFileCodeGenerator
+ Pages.List.Designer.cs
+
+
+
+
+ Pages.List.resx
+
diff --git a/BlazorApp/BlazorApp/Components/Card.razor b/BlazorApp/BlazorApp/Components/Card.razor
new file mode 100644
index 0000000..e814a9b
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Card.razor
@@ -0,0 +1,9 @@
+Card
+@typeparam TItem
+
+
+ @CardHeader(Item)
+ @CardBody(Item)
+ @CardFooter
+
+
diff --git a/BlazorApp/BlazorApp/Components/Card.razor.cs b/BlazorApp/BlazorApp/Components/Card.razor.cs
new file mode 100644
index 0000000..838cb8a
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Card.razor.cs
@@ -0,0 +1,21 @@
+using System;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp.Components
+{
+ public partial class Card
+ {
+ [Parameter]
+ public RenderFragment CardBody { get; set; }
+
+ [Parameter]
+ public RenderFragment CardFooter { get; set; }
+
+ [Parameter]
+ public RenderFragment CardHeader { get; set; }
+
+ [Parameter]
+ public TItem Item { get; set; }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Components/Crafting.razor b/BlazorApp/BlazorApp/Components/Crafting.razor
new file mode 100644
index 0000000..42dd978
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Crafting.razor
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
Available items:
+
+
+
+ @foreach (var item in Items)
+ {
+
+ }
+
+
+
+
+
+
+
Recipe
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Result
+
+
+
+
+
+
+
+
+
+
+
diff --git a/BlazorApp/BlazorApp/Components/Crafting.razor.cs b/BlazorApp/BlazorApp/Components/Crafting.razor.cs
new file mode 100644
index 0000000..f7578fc
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Crafting.razor.cs
@@ -0,0 +1,82 @@
+using System;
+using BlazorApp.Models;
+using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
+using System.Collections.ObjectModel;
+using System.Collections.Specialized;
+
+namespace BlazorApp.Components
+{
+ public partial class Crafting
+ {
+ private Item _recipeResult;
+
+ public Crafting()
+ {
+ Actions = new ObservableCollection();
+ Actions.CollectionChanged += OnActionsCollectionChanged;
+ this.RecipeItems = new List- { null, null, null, null, null, null, null, null, null };
+ }
+
+ public ObservableCollection
Actions { get; set; }
+ public Item CurrentDragItem { get; set; }
+
+ [Parameter]
+ public List- Items { get; set; }
+
+ public List
- RecipeItems { get; set; }
+
+ public Item RecipeResult
+ {
+ get => this._recipeResult;
+ set
+ {
+ if (this._recipeResult == value)
+ {
+ return;
+ }
+
+ this._recipeResult = value;
+ this.StateHasChanged();
+ }
+ }
+
+ [Parameter]
+ public List
Recipes { get; set; }
+
+ ///
+ /// Gets or sets the java script runtime.
+ ///
+ [Inject]
+ internal IJSRuntime JavaScriptRuntime { get; set; }
+
+ public void CheckRecipe()
+ {
+ RecipeResult = null;
+
+ // Get the current model
+ var currentModel = string.Join("|", this.RecipeItems.Select(s => s != null ? s.Name : string.Empty));
+
+ this.Actions.Add(new CraftingAction { Action = $"Items : {currentModel}" });
+
+ foreach (var craftingRecipe in Recipes)
+ {
+ // Get the recipe model
+ var recipeModel = string.Join("|", craftingRecipe.Have.SelectMany(s => s));
+
+ this.Actions.Add(new CraftingAction { Action = $"Recipe model : {recipeModel}" });
+
+ if (currentModel == recipeModel)
+ {
+ RecipeResult = craftingRecipe.Give;
+ }
+ }
+ }
+
+ private void OnActionsCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
+ {
+ JavaScriptRuntime.InvokeVoidAsync("Crafting.AddActions", e.NewItems);
+ }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Components/Crafting.razor.css b/BlazorApp/BlazorApp/Components/Crafting.razor.css
new file mode 100644
index 0000000..2a388f2
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Crafting.razor.css
@@ -0,0 +1,19 @@
+.css-grid {
+ grid-template-columns: repeat(4,minmax(0,1fr));
+ gap: 10px;
+ display: grid;
+ width: 286px;
+}
+
+.css-recipe {
+ grid-template-columns: repeat(3,minmax(0,1fr));
+ gap: 10px;
+ display: grid;
+ width: 212px;
+}
+
+.actions {
+ border: 1px solid black;
+ height: 250px;
+ overflow: scroll;
+}
diff --git a/BlazorApp/BlazorApp/Components/Crafting.razor.js b/BlazorApp/BlazorApp/Components/Crafting.razor.js
new file mode 100644
index 0000000..f222938
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/Crafting.razor.js
@@ -0,0 +1,20 @@
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/CraftingAction.cs b/BlazorApp/BlazorApp/Components/CraftingAction.cs
new file mode 100644
index 0000000..87cc02e
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/CraftingAction.cs
@@ -0,0 +1,13 @@
+using System;
+using BlazorApp.Models;
+
+namespace BlazorApp.Components
+{
+ public class CraftingAction
+ {
+ public string Action { get; set; }
+ public int Index { get; set; }
+ public Item Item { get; set; }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Components/CraftingItem.razor b/BlazorApp/BlazorApp/Components/CraftingItem.razor
new file mode 100644
index 0000000..e64e6cd
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/CraftingItem.razor
@@ -0,0 +1,13 @@
+
+
+ @if (Item != null)
+ {
+ @Item.DisplayName
+ }
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/CraftingItem.razor.cs b/BlazorApp/BlazorApp/Components/CraftingItem.razor.cs
new file mode 100644
index 0000000..5893a1f
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/CraftingItem.razor.cs
@@ -0,0 +1,68 @@
+using System;
+using BlazorApp.Models;
+using Blazorise;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp.Components
+{
+ public partial class CraftingItem
+ {
+ [Parameter]
+ public int Index { get; set; }
+
+ [Parameter]
+ public Item Item { get; set; }
+
+ [Parameter]
+ public bool NoDrop { get; set; }
+
+ [CascadingParameter]
+ public Crafting Parent { get; set; }
+
+ internal void OnDragEnter()
+ {
+ if (NoDrop)
+ {
+ return;
+ }
+
+ Parent.Actions.Add(new CraftingAction { Action = "Drag Enter", Item = this.Item, Index = this.Index });
+ }
+
+ internal void OnDragLeave()
+ {
+ if (NoDrop)
+ {
+ return;
+ }
+
+ Parent.Actions.Add(new CraftingAction { Action = "Drag Leave", Item = this.Item, Index = this.Index });
+ }
+
+ internal void OnDrop()
+ {
+ if (NoDrop)
+ {
+ return;
+ }
+
+ this.Item = Parent.CurrentDragItem;
+ Parent.RecipeItems[this.Index] = this.Item;
+
+ Parent.Actions.Add(new CraftingAction { Action = "Drop", Item = this.Item, Index = this.Index });
+
+ // Check recipe
+ Parent.CheckRecipe();
+ }
+
+ private void OnDragStart()
+ {
+ Parent.CurrentDragItem = this.Item;
+
+ Parent.Actions.Add(new CraftingAction { Action = "Drag Start", Item = this.Item, Index = this.Index });
+ }
+ }
+}
+
+
+
diff --git a/BlazorApp/BlazorApp/Components/CraftingItem.razor.css b/BlazorApp/BlazorApp/Components/CraftingItem.razor.css
new file mode 100644
index 0000000..b2d4521
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/CraftingItem.razor.css
@@ -0,0 +1,6 @@
+.item {
+ width: 64px;
+ height: 64px;
+ border: 1px solid;
+ overflow: hidden;
+}
diff --git a/BlazorApp/BlazorApp/Components/CraftingRecipe.cs b/BlazorApp/BlazorApp/Components/CraftingRecipe.cs
new file mode 100644
index 0000000..759bbb8
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/CraftingRecipe.cs
@@ -0,0 +1,12 @@
+using System;
+using BlazorApp.Models;
+
+namespace BlazorApp.Components
+{
+ public class CraftingRecipe
+ {
+ public Item Give { get; set; }
+ public List> Have { get; set; }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Components/MyFirstChildComponent.razor b/BlazorApp/BlazorApp/Components/MyFirstChildComponent.razor
new file mode 100644
index 0000000..592c4e4
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/MyFirstChildComponent.razor
@@ -0,0 +1,14 @@
+@code {
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+
+ [CascadingParameter]
+ public MyRootComponent RootComponent { get; set; }
+}
+
+
+
MyFirstChildComponent - @RootComponent.Text
+
+ @ChildContent
+
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/MyRootComponent.razor b/BlazorApp/BlazorApp/Components/MyRootComponent.razor
new file mode 100644
index 0000000..18895ba
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/MyRootComponent.razor
@@ -0,0 +1,16 @@
+@code {
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+
+ [Parameter]
+ public string Text { get; set; }
+}
+
+
+
MyRootComponent - @Text
+
+
+ @ChildContent
+
+
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/MySecondChildComponent.razor b/BlazorApp/BlazorApp/Components/MySecondChildComponent.razor
new file mode 100644
index 0000000..7d207e6
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/MySecondChildComponent.razor
@@ -0,0 +1,14 @@
+@code {
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+
+ [CascadingParameter]
+ public MyRootComponent RootComponent { get; set; }
+}
+
+
+
MySecondChildComponent - @RootComponent.Text
+
+ @ChildContent
+
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Components/ShowItems.razor b/BlazorApp/BlazorApp/Components/ShowItems.razor
new file mode 100644
index 0000000..f7c75f8
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/ShowItems.razor
@@ -0,0 +1,11 @@
+@typeparam TItem
+
+
+ @if ((Items?.Count ?? 0) != 0)
+ {
+ @foreach (var item in Items)
+ {
+ @ShowTemplate(item);
+ }
+ }
+
diff --git a/BlazorApp/BlazorApp/Components/ShowItems.razor.cs b/BlazorApp/BlazorApp/Components/ShowItems.razor.cs
new file mode 100644
index 0000000..f4fda81
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/ShowItems.razor.cs
@@ -0,0 +1,15 @@
+using System;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp.Components
+{
+ public partial class ShowItems
+ {
+ [Parameter]
+ public List Items { get; set; }
+
+ [Parameter]
+ public RenderFragment ShowTemplate { get; set; }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Components/TestRenderFragment.razor b/BlazorApp/BlazorApp/Components/TestRenderFragment.razor
new file mode 100644
index 0000000..e8ca13f
--- /dev/null
+++ b/BlazorApp/BlazorApp/Components/TestRenderFragment.razor
@@ -0,0 +1,7 @@
+TestRenderFragment
+
+@code {
+ [Parameter]
+ public RenderFragment ChildContent { get; set; }
+}
+
diff --git a/BlazorApp/BlazorApp/Controllers/CultureController.cs b/BlazorApp/BlazorApp/Controllers/CultureController.cs
new file mode 100644
index 0000000..4af37d9
--- /dev/null
+++ b/BlazorApp/BlazorApp/Controllers/CultureController.cs
@@ -0,0 +1,36 @@
+using System;
+using Microsoft.AspNetCore.Localization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace BlazorApp.Controllers
+{
+ ///
+ /// The culture controller.
+ ///
+ [Route("[controller]/[action]")]
+ public class CultureController : Controller
+ {
+ ///
+ /// Sets the culture.
+ ///
+ /// The culture.
+ /// The redirect URI.
+ ///
+ /// The action result.
+ ///
+ public IActionResult SetCulture(string culture, string redirectUri)
+ {
+ if (culture != null)
+ {
+ // Define a cookie with the selected culture
+ this.HttpContext.Response.Cookies.Append(
+ CookieRequestCultureProvider.DefaultCookieName,
+ CookieRequestCultureProvider.MakeCookieValue(
+ new RequestCulture(culture)));
+ }
+
+ return this.LocalRedirect(redirectUri);
+ }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Factories/ItemFactory.cs b/BlazorApp/BlazorApp/Factories/ItemFactory.cs
new file mode 100644
index 0000000..c58fa10
--- /dev/null
+++ b/BlazorApp/BlazorApp/Factories/ItemFactory.cs
@@ -0,0 +1,53 @@
+using System;
+using BlazorApp.Models;
+
+namespace BlazorApp.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
+
+ };
+ }
+
+ 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/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor b/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor
new file mode 100644
index 0000000..c3123c8
--- /dev/null
+++ b/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor
@@ -0,0 +1,10 @@
+
diff --git a/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor.cs b/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor.cs
new file mode 100644
index 0000000..ac365ac
--- /dev/null
+++ b/BlazorApp/BlazorApp/Modals/DeleteConfirmation.razor.cs
@@ -0,0 +1,40 @@
+using System;
+using BlazorApp.Models;
+using BlazorApp.Services;
+using Blazored.Modal;
+using Blazored.Modal.Services;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp.Modals
+{
+ public partial class DeleteConfirmation
+ {
+ [CascadingParameter]
+ public BlazoredModalInstance ModalInstance { get; set; }
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Parameter]
+ public int Id { get; set; }
+
+ private Item item = new Item();
+
+ protected override async Task OnInitializedAsync()
+ {
+ // Get the item
+ item = await DataService.GetById(Id);
+ }
+
+ void ConfirmDelete()
+ {
+ ModalInstance.CloseAsync(ModalResult.Ok(true));
+ }
+
+ void Cancel()
+ {
+ ModalInstance.CancelAsync();
+ }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Models/Cake.cs b/BlazorApp/BlazorApp/Models/Cake.cs
new file mode 100644
index 0000000..068e3af
--- /dev/null
+++ b/BlazorApp/BlazorApp/Models/Cake.cs
@@ -0,0 +1,11 @@
+using System;
+namespace BlazorApp.Models
+{
+ public class Cake
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public decimal Cost { get; set; }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Models/Item.cs b/BlazorApp/BlazorApp/Models/Item.cs
index 0eb9b53..9d26617 100644
--- a/BlazorApp/BlazorApp/Models/Item.cs
+++ b/BlazorApp/BlazorApp/Models/Item.cs
@@ -1,7 +1,7 @@
namespace BlazorApp.Models
{
public class Item
-{
+ {
public int Id { get; set; }
public string DisplayName { get; set; }
public string Name { get; set; }
@@ -11,5 +11,6 @@
public List RepairWith { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime? UpdatedDate { get; set; }
-}
+ public string ImageBase64 { get; set; }
+ }
}
diff --git a/BlazorApp/BlazorApp/Models/ItemModel.cs b/BlazorApp/BlazorApp/Models/ItemModel.cs
index 59ecd50..b640531 100644
--- a/BlazorApp/BlazorApp/Models/ItemModel.cs
+++ b/BlazorApp/BlazorApp/Models/ItemModel.cs
@@ -34,6 +34,8 @@ namespace BlazorApp.Models
[Required(ErrorMessage = "The image of the item is mandatory!")]
public byte[] ImageContent { get; set; }
+
+ public string ImageBase64 { get; set; }
}
}
diff --git a/BlazorApp/BlazorApp/Pages/Edit.razor b/BlazorApp/BlazorApp/Pages/Edit.razor
index 34d55a3..74d3978 100644
--- a/BlazorApp/BlazorApp/Pages/Edit.razor
+++ b/BlazorApp/BlazorApp/Pages/Edit.razor
@@ -2,4 +2,81 @@
Edit
-My paremeter: @Id
+
+
+
+
+
+
+ Display name:
+
+
+
+
+
+ Name:
+
+
+
+
+
+ Stack size:
+
+
+
+
+
+ Max durability:
+
+
+
+
+ Enchant categories:
+
+ @foreach (var item in enchantCategories)
+ {
+
+ OnEnchantCategoriesChange(item, e.Value))" checked="@(itemModel.EnchantCategories.Contains(item) ? "checked" : null)" />@item
+
+ }
+
+
+
+ Repair with:
+
+ @foreach (var item in repairWith)
+ {
+
+ OnRepairWithChange(item, e.Value))" checked="@(itemModel.RepairWith.Contains(item) ? "checked" : null)" />@item
+
+ }
+
+
+
+
+ Current Item image:
+ @if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png"))
+ {
+
+ }
+ else
+ {
+
+ }
+
+
+
+
+ Item image:
+
+
+
+
+
+ Accept Condition:
+
+
+
+
+ Submit
+
\ No newline at end of file
diff --git a/BlazorApp/BlazorApp/Pages/Edit.razor.cs b/BlazorApp/BlazorApp/Pages/Edit.razor.cs
index be21d60..7d1abe1 100644
--- a/BlazorApp/BlazorApp/Pages/Edit.razor.cs
+++ b/BlazorApp/BlazorApp/Pages/Edit.razor.cs
@@ -1,5 +1,9 @@
using System;
+using BlazorApp.Factories;
+using BlazorApp.Models;
+using BlazorApp.Services;
using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
namespace BlazorApp.Pages
{
@@ -8,6 +12,101 @@ namespace BlazorApp.Pages
[Parameter]
public int Id { get; set; }
+ ///
+ /// The default enchant categories.
+ ///
+ private List enchantCategories = new List() { "armor", "armor_head", "armor_chest", "weapon", "digger", "breakable", "vanishable" };
+
+ ///
+ /// The current item model
+ ///
+ private ItemModel itemModel = new()
+ {
+ EnchantCategories = new List(),
+ RepairWith = new List()
+ };
+
+ ///
+ /// 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" };
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
+ [Inject]
+ public IWebHostEnvironment WebHostEnvironment { get; set; }
+
+ protected override async Task OnInitializedAsync()
+ {
+ var item = await DataService.GetById(Id);
+
+ var fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/default.png");
+
+ if (File.Exists($"{WebHostEnvironment.WebRootPath}/images/{itemModel.Name}.png"))
+ {
+ fileContent = await File.ReadAllBytesAsync($"{WebHostEnvironment.WebRootPath}/images/{item.Name}.png");
+ }
+
+ // Set the model with the item
+ itemModel = ItemFactory.ToModel(item, fileContent);
+ }
+
+ private async void HandleValidSubmit()
+ {
+ await DataService.Update(Id, itemModel);
+
+ 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/BlazorApp/BlazorApp/Pages/Index.razor b/BlazorApp/BlazorApp/Pages/Index.razor
index b1a9fbd..5deb450 100644
--- a/BlazorApp/BlazorApp/Pages/Index.razor
+++ b/BlazorApp/BlazorApp/Pages/Index.razor
@@ -1,9 +1,48 @@
@page "/"
+@using System.Globalization
+@using BlazorApp.Components
Index
Hello, world!
-Welcome to your new app.
+
+
+
+
+
diff --git a/BlazorApp/BlazorApp/Pages/Index.razor.cs b/BlazorApp/BlazorApp/Pages/Index.razor.cs
new file mode 100644
index 0000000..b0e2eb7
--- /dev/null
+++ b/BlazorApp/BlazorApp/Pages/Index.razor.cs
@@ -0,0 +1,58 @@
+using System;
+using BlazorApp.Components;
+using BlazorApp.Models;
+using BlazorApp.Services;
+using Microsoft.AspNetCore.Components;
+
+namespace BlazorApp.Pages
+{
+ public partial class Index
+ {
+ /*
+ public List Cakes { get; set; }
+
+ protected override Task OnAfterRenderAsync(bool firstRender)
+ {
+ LoadCakes();
+ StateHasChanged();
+ return base.OnAfterRenderAsync(firstRender);
+ }
+
+ public void LoadCakes()
+ {
+ Cakes = new List
+ {
+ // items hidden for display purpose
+ new Cake
+ {
+ Id = 1,
+ Name = "Red Velvet",
+ Cost = 60
+ },
+ new Cake
+ {
+ Id = 2,
+ Name = "Black Forest",
+ Cost = 50
+ },
+ };
+ }
+ */
+
+ [Inject]
+ public IDataService DataService { get; set; }
+
+ public List- Items { get; set; } = new List
- ();
+
+ private List
Recipes { get; set; } = new List();
+
+ protected override async Task OnInitializedAsync()
+ {
+ await base.OnInitializedAsync();
+
+ Items = await DataService.List(0, await DataService.Count());
+ Recipes = await DataService.GetRecipes();
+ }
+ }
+}
+
diff --git a/BlazorApp/BlazorApp/Pages/List.razor b/BlazorApp/BlazorApp/Pages/List.razor
index 6ed4807..9fc6239 100644
--- a/BlazorApp/BlazorApp/Pages/List.razor
+++ b/BlazorApp/BlazorApp/Pages/List.razor
@@ -1,8 +1,7 @@
@page "/List"
@using BlazorApp.Models;
-
-List
+@Localizer["Title"]