Code u. Page zusammengefasst
This commit is contained in:
parent
bdf7cabc0a
commit
ccb0404477
@ -42,3 +42,51 @@
|
|||||||
<button class="btn btn-primary" @onclick="CloseDialog">Nee</button>
|
<button class="btn btn-primary" @onclick="CloseDialog">Nee</button>
|
||||||
</Footer>
|
</Footer>
|
||||||
</ModalComponent>
|
</ModalComponent>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,58 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
x
Reference in New Issue
Block a user