Удаление списка словаря

rename des popup de delete au passage
blazor
Antoine JOURDAIN 1 year ago
parent 0104e14baa
commit b35cb3509f

@ -1,7 +1,7 @@
<div class="simple-form">
<p>
Are you sure you want to delete @item.Name ?
Are you sure you want to delete user : @item.Name ?
</p>
<button @onclick="ConfirmDelete" class="btn btn-primary">Delete</button>

@ -6,7 +6,7 @@ using adminBlazor.Models;
namespace adminBlazor.Modals
{
public partial class DeleteConfirmation
public partial class UserDeleteConfirmation
{
[CascadingParameter]
public BlazoredModalInstance ModalInstance { get; set; }

@ -0,0 +1,10 @@
<div class="simple-form">
<p>
Are you sure you want to delete vocabulary list : @item.Name ?
</p>
<button @onclick="ConfirmDelete" class="btn btn-primary">Delete</button>
<button @onclick="Cancel" class="btn btn-secondary">Cancel</button>
</div>

@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Components;
using Blazored.Modal;
using Blazored.Modal.Services;
using adminBlazor.Services;
using adminBlazor.Models;
namespace adminBlazor.Modals
{
public partial class VocListDeleteConfirmation
{
[CascadingParameter]
public BlazoredModalInstance ModalInstance { get; set; }
[Inject]
public IVocListService VocListService { get; set; }
[Parameter]
public int Id { get; set; }
private VocabularyList item = new VocabularyList();
protected override async Task OnInitializedAsync()
{
// Get the item
item = await VocListService.GetById(Id);
}
void ConfirmDelete()
{
ModalInstance.CloseAsync(ModalResult.Ok(true));
}
void Cancel()
{
ModalInstance.CancelAsync();
}
}
}

@ -81,7 +81,7 @@ namespace adminBlazor.Pages
var parameters = new ModalParameters();
parameters.Add("Id", id);
var modal = Modal.Show<DeleteConfirmation>("Delete Confirmation", parameters);
var modal = Modal.Show<UserDeleteConfirmation>("Delete Confirmation", parameters);
var result = await modal.Result;
if (result.Cancelled)

@ -38,6 +38,7 @@
<DataGridColumn TItem="VocabularyList" Field="@nameof(VocabularyList.Id)" Caption="Modifier">
<DisplayTemplate>
<a href="editVoc/@(context.Id)" class="btn btn-primary"><i class="fa fa-edit"></i> Editer</a>
<button type="button" class="btn btn-primary" @onclick="() => OnDelete(context.Id)"><i class="fa fa-trash"></i> Supprimer</button>
</DisplayTemplate>
</DataGridColumn>
</DataGrid>

@ -67,5 +67,24 @@ namespace adminBlazor.Pages
totalVocList = await VocListService.Count();// an actual data for the current page
}
}
private async void OnDelete(int id)
{
var parameters = new ModalParameters();
parameters.Add("Id", id);
var modal = Modal.Show<VocListDeleteConfirmation>("Delete Confirmation", parameters);
var result = await modal.Result;
if (result.Cancelled)
{
return;
}
await VocListService.Delete(id);
// Reload the page
NavigationManager.NavigateTo("voc", true);
}
}
}

@ -110,9 +110,22 @@ namespace adminBlazor.Services
await _localStorage.SetItemAsync("voc", currentList);
}
public Task Delete(int id)
public async Task Delete(int id)
{
throw new NotImplementedException();
// Get the current data
var currentList = await _localStorage.GetItemAsync<List<VocabularyList>>("voc");
// Get the item int the list
var voc = currentList.FirstOrDefault(w => w.Id == id);
// Delete item in
currentList.Remove(voc);
// Delete the image
// Save the data
await _localStorage.SetItemAsync("voc", currentList);
}
}
}

Loading…
Cancel
Save