From e5aae853593b1fa29c8db5673eaf6043b8e27155 Mon Sep 17 00:00:00 2001 From: jopierron Date: Sat, 19 Nov 2022 08:24:57 +0100 Subject: [PATCH] continuation --- Modals/DeleteConfirmation.razor | 11 +++++++++ Modals/DeleteConfirmation.razor.cs | 38 ++++++++++++++++++++++++++++++ Pages/List.razor.cs | 26 +++++++++++++++++++- ProjetBlaser.csproj | 4 ---- 4 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 Modals/DeleteConfirmation.razor create mode 100644 Modals/DeleteConfirmation.razor.cs 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 @@ +
+ +

+ Are you sure you want to delete @item.DisplayName ? +

+ + + + +
+ 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 @@ - - - -