From ed12e92b46f99e5846d1bb59c2fadb251046e751 Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 10:12:43 +0100
Subject: [PATCH 01/18] Creating a data service, editing pages and registering
the data service
---
BlazorTp1/BlazorTp1.csproj | 9 +++
BlazorTp1/Pages/Add.razor.cs | 60 ++++---------------
BlazorTp1/Pages/List.razor.cs | 13 +----
BlazorTp1/Program.cs | 2 +
BlazorTp1/Services/DataLocalService.cs | 80 ++++++++++++++++++++++++++
BlazorTp1/Services/IDataService.cs | 10 ++++
6 files changed, 115 insertions(+), 59 deletions(-)
create mode 100644 BlazorTp1/Services/DataLocalService.cs
create mode 100644 BlazorTp1/Services/IDataService.cs
diff --git a/BlazorTp1/BlazorTp1.csproj b/BlazorTp1/BlazorTp1.csproj
index c0eacf6..3105fce 100644
--- a/BlazorTp1/BlazorTp1.csproj
+++ b/BlazorTp1/BlazorTp1.csproj
@@ -6,6 +6,11 @@
enable
+
+
+
+
+
@@ -13,4 +18,8 @@
+
+
+
+
diff --git a/BlazorTp1/Pages/Add.razor.cs b/BlazorTp1/Pages/Add.razor.cs
index 794e331..fc1fdf9 100644
--- a/BlazorTp1/Pages/Add.razor.cs
+++ b/BlazorTp1/Pages/Add.razor.cs
@@ -7,25 +7,11 @@ namespace BlazorTp1.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
///
@@ -35,44 +21,20 @@ namespace BlazorTp1.Pages
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();
- }
+ ///
+ /// 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" };
- // Determine the image name
- var fileName = new FileInfo($"{imagePathInfo}/{itemModel.Name}.png");
+ [Inject]
+ public IDataService DataService { get; set; }
- // Write the file content
- await File.WriteAllBytesAsync(fileName.FullName, itemModel.ImageContent);
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
- // Save the data
- await LocalStorage.SetItemAsync("data", currentData);
+ private async void HandleValidSubmit()
+ {
+ await DataService.Add(itemModel);
NavigationManager.NavigateTo("list");
}
diff --git a/BlazorTp1/Pages/List.razor.cs b/BlazorTp1/Pages/List.razor.cs
index 4fd69ef..fbab704 100644
--- a/BlazorTp1/Pages/List.razor.cs
+++ b/BlazorTp1/Pages/List.razor.cs
@@ -12,14 +12,11 @@ namespace BlazorTp1.Pages
private int totalItem;
[Inject]
- public HttpClient Http { get; set; }
+ public IDataService DataService { get; set; }
[Inject]
public IWebHostEnvironment WebHostEnvironment { get; set; }
- [Inject]
- public NavigationManager NavigationManager { get; set; }
-
private async Task OnReadData(DataGridReadDataEventArgs- e)
{
if (e.CancellationToken.IsCancellationRequested)
@@ -27,14 +24,10 @@ namespace BlazorTp1.Pages
return;
}
- // 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();
-
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
+ items = await DataService.List(e.Page, e.PageSize);
+ totalItem = await DataService.Count();
}
}
}
diff --git a/BlazorTp1/Program.cs b/BlazorTp1/Program.cs
index 8d82ec6..99989cb 100644
--- a/BlazorTp1/Program.cs
+++ b/BlazorTp1/Program.cs
@@ -22,6 +22,8 @@ builder.Services
builder.Services.AddBlazoredLocalStorage();
+builder.Services.AddScoped();
+
var app = builder.Build();
// Configure the HTTP request pipeline.
diff --git a/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs
new file mode 100644
index 0000000..0fc6b16
--- /dev/null
+++ b/BlazorTp1/Services/DataLocalService.cs
@@ -0,0 +1,80 @@
+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(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
+ });
+
+ // 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}/{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 the 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();
+ }
+}
\ No newline at end of file
diff --git a/BlazorTp1/Services/IDataService.cs b/BlazorTp1/Services/IDataService.cs
new file mode 100644
index 0000000..a49c3c5
--- /dev/null
+++ b/BlazorTp1/Services/IDataService.cs
@@ -0,0 +1,10 @@
+using System;
+
+public interface IDataService
+{
+ Task Add(ItemModel model);
+
+ Task Count();
+
+ Task
> List(int currentPage, int pageSize);
+}
From a6d1e275fe12ff65b176fb517f119d3e22816e1c Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 10:16:16 +0100
Subject: [PATCH 02/18] fixed missing headers
---
BlazorTp1/Program.cs | 2 +-
BlazorTp1/Services/DataLocalService.cs | 6 +++++-
BlazorTp1/Services/IDataService.cs | 3 ++-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/BlazorTp1/Program.cs b/BlazorTp1/Program.cs
index 99989cb..a4adb86 100644
--- a/BlazorTp1/Program.cs
+++ b/BlazorTp1/Program.cs
@@ -22,7 +22,7 @@ builder.Services
builder.Services.AddBlazoredLocalStorage();
-builder.Services.AddScoped();
+builder.Services.AddScoped();
var app = builder.Build();
diff --git a/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs
index 0fc6b16..ecde1df 100644
--- a/BlazorTp1/Services/DataLocalService.cs
+++ b/BlazorTp1/Services/DataLocalService.cs
@@ -1,4 +1,8 @@
-public class DataLocalService : IDataService
+using Blazored.LocalStorage;
+using BlazorTp1.Models;
+using Microsoft.AspNetCore.Components;
+
+public class DataLocalService : IDataService
{
private readonly HttpClient _http;
private readonly ILocalStorageService _localStorage;
diff --git a/BlazorTp1/Services/IDataService.cs b/BlazorTp1/Services/IDataService.cs
index a49c3c5..1b5ac23 100644
--- a/BlazorTp1/Services/IDataService.cs
+++ b/BlazorTp1/Services/IDataService.cs
@@ -1,4 +1,5 @@
-using System;
+using BlazorTp1.Models;
+using System;
public interface IDataService
{
From 9f69b0c26c6326ef4bc76646171bafeec0464e66 Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 10:24:37 +0100
Subject: [PATCH 03/18] new methods to IDataService and DataLocalService
---
BlazorTp1/Services/DataLocalService.cs | 74 ++++++++++++++++++++++++++
BlazorTp1/Services/IDataService.cs | 4 ++
2 files changed, 78 insertions(+)
diff --git a/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs
index ecde1df..7268f8d 100644
--- a/BlazorTp1/Services/DataLocalService.cs
+++ b/BlazorTp1/Services/DataLocalService.cs
@@ -51,6 +51,8 @@ public class DataLocalService : IDataService
imagePathInfo.Create();
}
+
+
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
@@ -81,4 +83,76 @@ public class DataLocalService : IDataService
return (await _localStorage.GetItemAsync- ("data")).Skip((currentPage - 1) * pageSize).Take(pageSize).ToList();
}
+
+ //new methods
+
+ 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
+ var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images");
+
+ // Check if the folder "images" exist
+ if (!imagePathInfo.Exists)
+ {
+ imagePathInfo.Create();
+ }
+
+ // Delete the previous image
+ if (item.Name != model.Name)
+ {
+ var oldFileName = new FileInfo($"{imagePathInfo}/{item.Name}.png");
+
+ if (oldFileName.Exists)
+ {
+ File.Delete(oldFileName.FullName);
+ }
+ }
+
+ // Determine the image name
+ 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
+ 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;
+
+ // Save the data
+ await _localStorage.SetItemAsync("data", currentData);
+ }
}
\ No newline at end of file
diff --git a/BlazorTp1/Services/IDataService.cs b/BlazorTp1/Services/IDataService.cs
index 1b5ac23..c489a15 100644
--- a/BlazorTp1/Services/IDataService.cs
+++ b/BlazorTp1/Services/IDataService.cs
@@ -8,4 +8,8 @@ public interface IDataService
Task Count();
Task> List(int currentPage, int pageSize);
+
+ Task- GetById(int id);
+
+ Task Update(int id, ItemModel item);
}
From 691f051327192c4652a6c422744e854b234837c8 Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 10:27:26 +0100
Subject: [PATCH 04/18] Edit action added
---
BlazorTp1/Pages/List.razor | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/BlazorTp1/Pages/List.razor b/BlazorTp1/Pages/List.razor
index 640d9f2..9080e62 100644
--- a/BlazorTp1/Pages/List.razor
+++ b/BlazorTp1/Pages/List.razor
@@ -42,5 +42,10 @@
@(string.Join(", ", ((Item)context).RepairWith))
-
+
+
+
+ Editer
+
+
From ed8e380f4e2cdcb704a1dc71883c117a1b32601b Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 11:08:32 +0100
Subject: [PATCH 05/18] Creation of the form + using the model
---
BlazorTp1/Pages/Edit.cs | 118 +++++++++++++++++++++++++++++++++++++
BlazorTp1/Pages/Edit.razor | 82 ++++++++++++++++++++++++++
2 files changed, 200 insertions(+)
create mode 100644 BlazorTp1/Pages/Edit.cs
create mode 100644 BlazorTp1/Pages/Edit.razor
diff --git a/BlazorTp1/Pages/Edit.cs b/BlazorTp1/Pages/Edit.cs
new file mode 100644
index 0000000..963ff13
--- /dev/null
+++ b/BlazorTp1/Pages/Edit.cs
@@ -0,0 +1,118 @@
+using BlazorTp1.Models;
+using Microsoft.AspNetCore.Components;
+using Microsoft.AspNetCore.Components.Forms;
+
+namespace BlazorTp1.Pages
+{
+ public partial class Edit
+ {
+ [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 = 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
+ };
+ }
+
+ 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/BlazorTp1/Pages/Edit.razor b/BlazorTp1/Pages/Edit.razor
new file mode 100644
index 0000000..c18f772
--- /dev/null
+++ b/BlazorTp1/Pages/Edit.razor
@@ -0,0 +1,82 @@
+@page "/edit/{Id:int}"
+
+
Edit
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Enchant categories:
+
+ @foreach (var item in enchantCategories)
+ {
+
+ }
+
+
+
+ Repair with:
+
+ @foreach (var item in repairWith)
+ {
+
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
From 076c444c705ff61da33037eb003fe193e6eed7c8 Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sat, 12 Nov 2022 11:16:33 +0100
Subject: [PATCH 06/18] Factory pattern created and implemented in Edit.cs
---
BlazorTp1/Factories/ItemFactory.cs | 48 ++++++++++++++++++++++++++
BlazorTp1/Pages/Edit.cs | 15 ++------
BlazorTp1/Services/DataLocalService.cs | 23 ++----------
3 files changed, 54 insertions(+), 32 deletions(-)
create mode 100644 BlazorTp1/Factories/ItemFactory.cs
diff --git a/BlazorTp1/Factories/ItemFactory.cs b/BlazorTp1/Factories/ItemFactory.cs
new file mode 100644
index 0000000..2a7e9fe
--- /dev/null
+++ b/BlazorTp1/Factories/ItemFactory.cs
@@ -0,0 +1,48 @@
+using BlazorTp1.Models;
+
+namespace BlazorTp1.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/BlazorTp1/Pages/Edit.cs b/BlazorTp1/Pages/Edit.cs
index 963ff13..cdf97ab 100644
--- a/BlazorTp1/Pages/Edit.cs
+++ b/BlazorTp1/Pages/Edit.cs
@@ -1,4 +1,5 @@
-using BlazorTp1.Models;
+using BlazorTp1.Factories;
+using BlazorTp1.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
@@ -49,17 +50,7 @@ namespace BlazorTp1.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/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs
index 7268f8d..03de625 100644
--- a/BlazorTp1/Services/DataLocalService.cs
+++ b/BlazorTp1/Services/DataLocalService.cs
@@ -1,4 +1,5 @@
using Blazored.LocalStorage;
+using BlazorTp1.Factories;
using BlazorTp1.Models;
using Microsoft.AspNetCore.Components;
@@ -30,17 +31,7 @@ public class DataLocalService : IDataService
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");
@@ -51,8 +42,6 @@ public class DataLocalService : IDataService
imagePathInfo.Create();
}
-
-
// Determine the image name
var fileName = new FileInfo($"{imagePathInfo}/{model.Name}.png");
@@ -144,13 +133,7 @@ public class DataLocalService : IDataService
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);
From 2049302c564a4cb441972e11103a8ac3920eebca Mon Sep 17 00:00:00 2001
From: runtenick
Date: Sun, 13 Nov 2022 08:45:28 +0100
Subject: [PATCH 07/18] Modal added
---
BlazorTp1/App.razor | 26 ++++++++++++++------------
BlazorTp1/BlazorTp1.csproj | 1 +
BlazorTp1/Pages/List.razor | 1 +
BlazorTp1/Pages/List.razor.cs | 4 ++++
BlazorTp1/Pages/_Layout.cshtml | 3 +++
BlazorTp1/Program.cs | 3 +++
BlazorTp1/Services/DataLocalService.cs | 24 ++++++++++++++++++++++++
BlazorTp1/Services/IDataService.cs | 2 ++
BlazorTp1/_Imports.razor | 2 ++
9 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/BlazorTp1/App.razor b/BlazorTp1/App.razor
index 6fd3ed1..36bc2e6 100644
--- a/BlazorTp1/App.razor
+++ b/BlazorTp1/App.razor
@@ -1,12 +1,14 @@
-
-
-
-
-
-
- Not found
-
- Sorry, there's nothing at this address.
-
-
-
+
+
+
+
+
+
+
+ Not found
+
+ Sorry, there's nothing at this address.
+
+
+
+
diff --git a/BlazorTp1/BlazorTp1.csproj b/BlazorTp1/BlazorTp1.csproj
index 3105fce..ce09efd 100644
--- a/BlazorTp1/BlazorTp1.csproj
+++ b/BlazorTp1/BlazorTp1.csproj
@@ -13,6 +13,7 @@
+
diff --git a/BlazorTp1/Pages/List.razor b/BlazorTp1/Pages/List.razor
index 9080e62..1bd5c64 100644
--- a/BlazorTp1/Pages/List.razor
+++ b/BlazorTp1/Pages/List.razor
@@ -46,6 +46,7 @@
Editer
+
diff --git a/BlazorTp1/Pages/List.razor.cs b/BlazorTp1/Pages/List.razor.cs
index fbab704..1295274 100644
--- a/BlazorTp1/Pages/List.razor.cs
+++ b/BlazorTp1/Pages/List.razor.cs
@@ -30,5 +30,9 @@ namespace BlazorTp1.Pages
totalItem = await DataService.Count();
}
}
+ private void OnDelete(int id)
+ {
+
+ }
}
}
diff --git a/BlazorTp1/Pages/_Layout.cshtml b/BlazorTp1/Pages/_Layout.cshtml
index 641ca97..a30151a 100644
--- a/BlazorTp1/Pages/_Layout.cshtml
+++ b/BlazorTp1/Pages/_Layout.cshtml
@@ -34,5 +34,8 @@
+
+
+