85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using SQLitePCL;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using CocktailWeb.Data;
|
|
|
|
namespace CocktailWeb.Pages
|
|
{
|
|
public partial class Flaschen
|
|
{
|
|
public bool CreateFormVisible { get; set; }
|
|
public bool EditFormVisible { get; set; }
|
|
|
|
public Flasche? FlascheToCreate { get; set; }
|
|
public Flasche? FlascheToUpdate { get; set; }
|
|
|
|
public List<Flasche>? FlaschenListe { get; set; }
|
|
|
|
|
|
private DbDataContext? _DataContext;
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
CreateFormVisible = false;
|
|
await ShowFlaschen();
|
|
}
|
|
|
|
public void ShowCreateForm()
|
|
{
|
|
FlascheToCreate = new Flasche();
|
|
CreateFormVisible = true;
|
|
}
|
|
|
|
public async Task CreateNewFlasche()
|
|
{
|
|
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
|
|
|
|
if (FlascheToCreate != null && _DataContext != null)
|
|
{
|
|
_DataContext.Flaschen.Add(FlascheToCreate);
|
|
await _DataContext.SaveChangesAsync();
|
|
}
|
|
CreateFormVisible = false;
|
|
await ShowFlaschen();
|
|
}
|
|
|
|
public async Task ShowFlaschen()
|
|
{
|
|
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null)
|
|
{
|
|
FlaschenListe = await _DataContext.Flaschen.OrderBy(f => f.Name).ToListAsync();
|
|
}
|
|
|
|
}
|
|
|
|
public async Task ShowEditForm(Flasche flasche)
|
|
{
|
|
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
|
|
FlascheToUpdate = _DataContext.Flaschen.FirstOrDefault(f => f.Id == flasche.Id);
|
|
EditFormVisible = true;
|
|
}
|
|
|
|
public async Task UpdateEmployee(Flasche flasche)
|
|
{
|
|
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null && flasche != null)
|
|
{
|
|
_DataContext.Flaschen.Update(flasche);
|
|
await _DataContext.SaveChangesAsync();
|
|
}
|
|
EditFormVisible = false;
|
|
}
|
|
|
|
public async Task DeleteFlasche(Flasche flasche)
|
|
{
|
|
_DataContext ??= await FlascheDataContextFactory.CreateDbContextAsync();
|
|
if (_DataContext != null && flasche != null)
|
|
{
|
|
_DataContext.Flaschen.Remove(flasche);
|
|
await _DataContext.SaveChangesAsync();
|
|
}
|
|
await ShowFlaschen();
|
|
}
|
|
|
|
}
|
|
}
|