diff --git a/CocktailWeb/Pages/Settings/Maschine.razor b/CocktailWeb/Pages/Settings/Maschine.razor index 0b52210..f4528e2 100644 --- a/CocktailWeb/Pages/Settings/Maschine.razor +++ b/CocktailWeb/Pages/Settings/Maschine.razor @@ -2,6 +2,8 @@ @using Microsoft.EntityFrameworkCore @using CocktailWeb.Data @using Microsoft.AspNetCore.Components.Sections +@using CocktailWeb.Shared + @inject IDbContextFactory DataContextFactory; Maschineneinstellungen @@ -14,7 +16,7 @@
@foreach (Filler f in Fillers.Where(f => f.Type == Filler.FillerType.Pourer)) { - + @f.Pos - @f.Flasche?.Name } @@ -24,64 +26,30 @@
@foreach (Filler f in Fillers.Where(f => f.Type == Filler.FillerType.Pump)) { - + @f.Pos - @f.Flasche?.Name }
- - - -@code { - private DbDataContext? _DataContext; - private List Fillers { get; set; } = new(); - private List Flaschen { get; set; } = new(); - - protected override async Task OnInitializedAsync() - { - await ShowFillers(); - } - - private async Task ShowFillers() - { - _DataContext ??= await DataContextFactory.CreateDbContextAsync(); - if (_DataContext != null) - { - Fillers = await _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToListAsync(); - Flaschen = await _DataContext.Flaschen.OrderBy(fl => fl.Name).ToListAsync(); - } - } -} + + Flasche auswählen + +
    +
  • + +
  • + @foreach (Flasche fl in Flaschen) + { +
  • + +
  • + } +
+ +
+ + +
+
diff --git a/CocktailWeb/Pages/Settings/Maschine.razor.cs b/CocktailWeb/Pages/Settings/Maschine.razor.cs index c365048..2ed268c 100644 --- a/CocktailWeb/Pages/Settings/Maschine.razor.cs +++ b/CocktailWeb/Pages/Settings/Maschine.razor.cs @@ -1,6 +1,69 @@ -namespace CocktailWeb.Pages.Settings +using CocktailWeb.Data; +using Microsoft.AspNetCore.Components.Web; + +using Microsoft.EntityFrameworkCore; +namespace CocktailWeb.Pages.Settings { partial class Maschine { + private DbDataContext? _DataContext; + private List Fillers { get; set; } = new(); + private List Flaschen { get; set; } = new(); + + private Filler? SelectedFiller { get; set; } + + private Flasche? SelectedFlasche { get; set; } + + private ModalComponent modal = null!; + + protected override async Task OnInitializedAsync() + { + await ShowFillers(); + } + + private async Task ShowFillers() + { + _DataContext ??= await DataContextFactory.CreateDbContextAsync(); + if (_DataContext != null) + { + Fillers = await _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToListAsync(); + Flaschen = await _DataContext.Flaschen.OrderBy(fl => fl.Name).ToListAsync(); + } + } + + public async Task OpenSelectionDialog(MouseEventArgs e, Filler f) + { + SelectedFiller = f; + SelectedFlasche = f.Flasche; + await modal.OpenModal(); + } + + + public void SelectFlasche(MouseEventArgs e, Flasche? fl) + { + SelectedFlasche = fl; + } + + private async Task SaveSelection(MouseEventArgs e) + { + if (SelectedFiller != null) + { + SelectedFiller.Flasche = SelectedFlasche; + _DataContext ??= await DataContextFactory.CreateDbContextAsync(); + if (_DataContext != null) + { + _DataContext.Fillers.Update(SelectedFiller); + await _DataContext.SaveChangesAsync(); + } + } + await CloseDialog(); + } + + private async Task CloseDialog() + { + SelectedFiller = null; + SelectedFlasche = null; + await modal.Close(); + } } }