59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using CocktailWeb;
|
|
using CocktailWeb.Data;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace CocktailWeb.Pages.Settings
|
|
{
|
|
public partial class Cocktails
|
|
{
|
|
private DbDataContext? _DataContext;
|
|
private ModalComponent modal = null!;
|
|
private Cocktail? SelectedCocktail;
|
|
|
|
private List<Cocktail> CocktailListe { get; set; } = new();
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ShowCocktails();
|
|
}
|
|
|
|
private async Task ShowCocktails()
|
|
{
|
|
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null)
|
|
{
|
|
CocktailListe = await _DataContext.Cocktails.OrderBy(f => f.Name).ToListAsync();
|
|
}
|
|
}
|
|
|
|
private async Task ConfirmDelete(Cocktail c)
|
|
{
|
|
SelectedCocktail = c;
|
|
await modal.OpenModal();
|
|
}
|
|
|
|
private async Task CloseDialog()
|
|
{
|
|
SelectedCocktail = null;
|
|
await modal.Close();
|
|
}
|
|
private async Task DeleteCocktail(MouseEventArgs e)
|
|
{
|
|
if (SelectedCocktail != null)
|
|
{
|
|
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null)
|
|
{
|
|
_DataContext.Cocktails.Remove(SelectedCocktail);
|
|
await _DataContext.SaveChangesAsync();
|
|
await ShowCocktails();
|
|
}
|
|
}
|
|
await CloseDialog();
|
|
}
|
|
}
|
|
}
|