From 2049302c564a4cb441972e11103a8ac3920eebca Mon Sep 17 00:00:00 2001 From: runtenick Date: Sun, 13 Nov 2022 08:45:28 +0100 Subject: [PATCH] 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 @@ + + + diff --git a/BlazorTp1/Program.cs b/BlazorTp1/Program.cs index a4adb86..993a31c 100644 --- a/BlazorTp1/Program.cs +++ b/BlazorTp1/Program.cs @@ -3,6 +3,7 @@ using Blazorise; using Blazorise.Bootstrap; using Blazorise.Icons.FontAwesome; using BlazorTp1.Data; +using Blazored.Modal; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Web; @@ -24,6 +25,8 @@ builder.Services.AddBlazoredLocalStorage(); builder.Services.AddScoped(); +builder.Services.AddBlazoredModal(); + var app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/BlazorTp1/Services/DataLocalService.cs b/BlazorTp1/Services/DataLocalService.cs index 03de625..367f128 100644 --- a/BlazorTp1/Services/DataLocalService.cs +++ b/BlazorTp1/Services/DataLocalService.cs @@ -138,4 +138,28 @@ public class DataLocalService : IDataService // 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 + var imagePathInfo = new DirectoryInfo($"{_webHostEnvironment.WebRootPath}/images"); + var fileName = new FileInfo($"{imagePathInfo}/{item.Name}.png"); + + if (fileName.Exists) + { + File.Delete(fileName.FullName); + } + + // 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 c489a15..c621463 100644 --- a/BlazorTp1/Services/IDataService.cs +++ b/BlazorTp1/Services/IDataService.cs @@ -12,4 +12,6 @@ public interface IDataService Task GetById(int id); Task Update(int id, ItemModel item); + + Task Delete(int id); } diff --git a/BlazorTp1/_Imports.razor b/BlazorTp1/_Imports.razor index 009cdfc..fb7258e 100644 --- a/BlazorTp1/_Imports.razor +++ b/BlazorTp1/_Imports.razor @@ -9,3 +9,5 @@ @using BlazorTp1 @using BlazorTp1.Shared @using Blazorise.DataGrid +@using Blazored.Modal +@using Blazored.Modal.Services \ No newline at end of file