91 lines
2.7 KiB
Plaintext
91 lines
2.7 KiB
Plaintext
@page "/settings/glasses"
|
|
@using CocktailWeb.Data
|
|
@using Microsoft.AspNetCore.Components.Sections
|
|
@using Microsoft.EntityFrameworkCore
|
|
@inject IDbContextFactory<DbDataContext> DataContextFactory
|
|
|
|
<SectionContent SectionId="TopRow.Title">
|
|
<label>Einstellungen - Gläser</label>
|
|
</SectionContent>
|
|
|
|
|
|
<a class="btn btn-primary mb-3" href="/settings/glasses/edit">Glas hinzufügen</a>
|
|
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover table-bordered table-dark border-dark">
|
|
<tbody>
|
|
@foreach (Glas g in GlassList)
|
|
{
|
|
<tr>
|
|
<td class="p-0" style="width:64px"><img src="@g.ImageURL" style="max-width:100%; max-height:auto;" /></td>
|
|
<td style="vertical-align:middle;">@g.DisplayName</td>
|
|
<td style="text-align:right; vertical-align:middle;">
|
|
<a class="btn btn-primary" href="/settings/glasses/edit/@g.Id">Bearbeiten</a>
|
|
<button name="submit" type="submit" class="btn btn-outline-danger" @onclick="() => ConfirmDeleteAsync(g)">Löschen</button>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<ModalComponent @ref="modal">
|
|
<Title>Löschen bestätigen</Title>
|
|
<Body>
|
|
Willst du das Glas wirklich löschen?
|
|
</Body>
|
|
<Footer>
|
|
<button class="btn btn-danger" @onclick="DeleteGlassAsync">Jo</button>
|
|
<button class="btn btn-primary" @onclick="CloseDialogAsync">Nee</button>
|
|
</Footer>
|
|
</ModalComponent>
|
|
|
|
@code {
|
|
private List<Glas> GlassList = new();
|
|
private DbDataContext? _DataContext;
|
|
|
|
private ModalComponent modal = null!;
|
|
private Glas? SelectedGlas;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await ShowGlassesAsync();
|
|
}
|
|
|
|
private async Task ShowGlassesAsync()
|
|
{
|
|
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null)
|
|
{
|
|
GlassList = _DataContext.Glasses.OrderBy(g => g.Fuellmenge).ToList();
|
|
}
|
|
}
|
|
|
|
private async Task ConfirmDeleteAsync(Glas g)
|
|
{
|
|
SelectedGlas = g;
|
|
await modal.ShowAsync();
|
|
}
|
|
|
|
private async Task DeleteGlassAsync()
|
|
{
|
|
if (SelectedGlas == null) return;
|
|
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null)
|
|
{
|
|
_DataContext.Glasses.Remove(SelectedGlas);
|
|
await _DataContext.SaveChangesAsync();
|
|
await ShowGlassesAsync();
|
|
}
|
|
await CloseDialogAsync();
|
|
}
|
|
|
|
private async Task CloseDialogAsync()
|
|
{
|
|
SelectedGlas = null;
|
|
await modal.CloseAsync();
|
|
}
|
|
|
|
|
|
}
|