diff --git a/Modals/DeleteConfirmation.razor b/Modals/DeleteConfirmation.razor
new file mode 100644
index 0000000..a8e5548
--- /dev/null
+++ b/Modals/DeleteConfirmation.razor
@@ -0,0 +1,11 @@
+
+
diff --git a/Modals/DeleteConfirmation.razor.cs b/Modals/DeleteConfirmation.razor.cs
new file mode 100644
index 0000000..20d0790
--- /dev/null
+++ b/Modals/DeleteConfirmation.razor.cs
@@ -0,0 +1,38 @@
+using Blazored.Modal;
+using Blazored.Modal.Services;
+using Microsoft.AspNetCore.Components;
+using ProjetBlaser.Models;
+using ProjetBlaser.Services;
+
+namespace ProjetBlaser.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/Pages/List.razor.cs b/Pages/List.razor.cs
index 6c0e92e..c464bd9 100644
--- a/Pages/List.razor.cs
+++ b/Pages/List.razor.cs
@@ -1,6 +1,9 @@
using Blazored.LocalStorage;
+using Blazored.Modal;
+using Blazored.Modal.Services;
using Blazorise.DataGrid;
using Microsoft.AspNetCore.Components;
+using ProjetBlaser.Modals;
using ProjetBlaser.Models;
using ProjetBlaser.Services;
@@ -31,9 +34,30 @@ namespace ProjetBlaser.Pages
totalItem = await DataService.Count();
}
}
- private void OnDelete(int id)
+ [Inject]
+ public NavigationManager NavigationManager { get; set; }
+
+ [CascadingParameter]
+ public IModalService Modal { get; set; }
+
+ 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);
}
+
}
}
diff --git a/ProjetBlaser.csproj b/ProjetBlaser.csproj
index 6c93f4c..64d367c 100644
--- a/ProjetBlaser.csproj
+++ b/ProjetBlaser.csproj
@@ -14,8 +14,4 @@
-
-
-
-