Code u. Page zusammengefasst
This commit is contained in:
parent
bdf7cabc0a
commit
ccb0404477
@ -21,7 +21,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="p-0" style="width:64px"><img src="@c.ImageURL" style="max-width:100%; max-height:auto;" /></td>
|
<td class="p-0" style="width:64px"><img src="@c.ImageURL" style="max-width:100%; max-height:auto;" /></td>
|
||||||
<td style="vertical-align:middle;">@c.Name</td>
|
<td style="vertical-align:middle;">@c.Name</td>
|
||||||
<td style="text-align:right; vertical-align:middle;" >
|
<td style="text-align:right; vertical-align:middle;">
|
||||||
<a class="btn btn-primary" href="/settings/cocktails/edit/@c.Id">Bearbeiten</a>
|
<a class="btn btn-primary" href="/settings/cocktails/edit/@c.Id">Bearbeiten</a>
|
||||||
<button name="submit" type="submit" class="btn btn-outline-danger" @onclick="() => ConfirmDelete(c)">Löschen</button>
|
<button name="submit" type="submit" class="btn btn-outline-danger" @onclick="() => ConfirmDelete(c)">Löschen</button>
|
||||||
</td>
|
</td>
|
||||||
@ -41,4 +41,52 @@
|
|||||||
<button class="btn btn-danger" @onclick="DeleteCocktail">Jo</button>
|
<button class="btn btn-danger" @onclick="DeleteCocktail">Jo</button>
|
||||||
<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