Stärkeauswahl eingebaut und erstellen vom CocktailCode hinzugefügt
This commit is contained in:
parent
2e10170636
commit
b704dbc30e
@ -17,46 +17,95 @@
|
|||||||
@if (SelectedCocktail == null)
|
@if (SelectedCocktail == null)
|
||||||
{
|
{
|
||||||
<h3>Cocktail konnte nicht gefunden werden</h3>
|
<h3>Cocktail konnte nicht gefunden werden</h3>
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<div class="card mb-3" style="max-width: 540px;">
|
<div class="d-flex gap-3">
|
||||||
<div class="row g-0">
|
<div class="card mb-3 w-100">
|
||||||
<div class="col-md-4">
|
<div class="row g-0">
|
||||||
<img src="@SelectedCocktail.ImageURL" class="img-fluid rounded-start" alt="...">
|
<div class="col-md-8">
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">Einstellungen</h5>
|
||||||
|
<p class="card-text">
|
||||||
|
<h6>
|
||||||
|
Stärke
|
||||||
|
</h6>
|
||||||
|
<div class="btn-group" role="group">
|
||||||
|
<button @onclick="() => SetIntensity(-60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -60 ? "" : "outline-")success"><i class="bi bi-peace fs-5"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(-40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -40 ? "" : "outline-")success"><i class="bi bi-dash fs-5"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(-20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity <= -20 ? "" : "outline-")success"><i class="bi bi-dash"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(0)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity == 0 ? "" : "")warning"><i class="bi bi-circle"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(20)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 20 ? "" : "outline-")danger"><i class="bi bi-plus"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(40)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 40 ? "" : "outline-")danger"><i class="bi bi-plus fs-5"></i></button>
|
||||||
|
<button @onclick="() => SetIntensity(60)" class="btn @(SelectedCocktail.IsAlcoholic ? "" : "disabled") btn-@(DrinkIntensity >= 60 ? "" : "outline-")danger"><i class="bi bi-radioactive fs-5"></i></button>
|
||||||
|
</div>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
@if (ErrorMessage != null)
|
||||||
|
{
|
||||||
|
<div class="alert alert-danger" role="alert">
|
||||||
|
@ErrorMessage
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
@if(CocktailCode != null)
|
||||||
|
{
|
||||||
|
<div class="alert alert-dark" style="white-space: pre-line" role="alert">
|
||||||
|
@CocktailCode
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
<button class="btn btn-primary" @onclick=CreateCocktailCode>Lets goooooo!</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-8">
|
</div>
|
||||||
<div class="card-body">
|
<div class="card mb-3 w-100">
|
||||||
<h5 class="card-title">@SelectedCocktail.Name</h5>
|
<div class="row g-0">
|
||||||
<p class="card-text">
|
<div class="col-md-4">
|
||||||
<h6>Zutaten:</h6>
|
<img src="@SelectedCocktail.ImageURL" class="img-fluid rounded-start" alt="...">
|
||||||
<ul>
|
</div>
|
||||||
@foreach (var Zutat in SelectedCocktail.Cocktailflaschen.OrderBy(f => f.Reihenfolge))
|
<div class="col-md-8">
|
||||||
{
|
<div class="card-body">
|
||||||
@if (MaschinenFiller != null && MaschinenFiller.Exists(f => f.Flasche == Zutat.Flasche))
|
<h5 class="card-title">@SelectedCocktail.Name</h5>
|
||||||
{
|
<p class="card-text">
|
||||||
<li>@Zutat.Flasche?.Name (@Zutat.Menge ml)</li>
|
<h6>Rezept:</h6>
|
||||||
|
<table class="table-primary table-borderless w-100">
|
||||||
|
@{
|
||||||
|
int i = 1;
|
||||||
}
|
}
|
||||||
else
|
@foreach (var Zutat in SelectedCocktail.Cocktailflaschen.OrderBy(f => f.Reihenfolge))
|
||||||
{
|
{
|
||||||
@* Zutat nicht in MaschinenFiller gefunden - Daher ist Maschine nicht damit bestückt*@
|
<tr class="@(ZutatInMaschine(Zutat) ? "" : "text-danger")">
|
||||||
<li class="text-danger">@Zutat.Flasche?.Name (@Zutat.Menge ml) (nicht geladen)</li>
|
<td>@i.</td>
|
||||||
|
<td>@Zutat.Flasche?.Name</td>
|
||||||
|
<td class="text-end">@Zutat.Menge ml</td>
|
||||||
|
@if (DrinkIntensity != 0)
|
||||||
|
{
|
||||||
|
<td>=></td>
|
||||||
|
<td class="text-end">@ModifiedCocktail?.Cocktailflaschen.First(cf => cf.FlascheID == Zutat.FlascheID).Menge ml</td>
|
||||||
|
}
|
||||||
|
<td class="text-end">@(ZutatInMaschine(Zutat) ? "" : "fehlt")</td>
|
||||||
|
</tr>
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
<tr>
|
||||||
</ul>
|
<td></td>
|
||||||
</p>
|
<td>Gesamt</td>
|
||||||
|
<td class="text-end">@SelectedCocktail.Cocktailflaschen.Sum(cf => cf.Menge) ml</td>
|
||||||
|
@if (DrinkIntensity != 0)
|
||||||
|
{
|
||||||
|
<td>=></td>
|
||||||
|
<td class="text-end">@ModifiedCocktail?.Cocktailflaschen.Sum(cf => cf.Menge) ml</td>
|
||||||
|
}
|
||||||
|
<td class="text-end"></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if (ValideMische)
|
|
||||||
{
|
|
||||||
<button class="btn btn-primary">Lets goooooo!</button>
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
<button class="btn btn-outline-primary">Lets goooooo!</button>
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -65,21 +114,133 @@ else
|
|||||||
public string? CocktailId { get; set; }
|
public string? CocktailId { get; set; }
|
||||||
private DbDataContext? _DataContext;
|
private DbDataContext? _DataContext;
|
||||||
private Cocktail? SelectedCocktail;
|
private Cocktail? SelectedCocktail;
|
||||||
|
private Cocktail? ModifiedCocktail;
|
||||||
private List<Filler>? MaschinenFiller;
|
private List<Filler>? MaschinenFiller;
|
||||||
|
//private List<CocktailFlasche> ModifiedCocktailRecipe = new();
|
||||||
|
|
||||||
private bool ValideMische = true;
|
private int DrinkIntensity = 0;
|
||||||
|
|
||||||
|
private string? ErrorMessage;
|
||||||
|
private string? CocktailCode;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(CocktailId);
|
int id = Convert.ToInt32(CocktailId);
|
||||||
|
|
||||||
|
//Staerke_Off.Add();
|
||||||
|
|
||||||
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
_DataContext ??= await DataContextFactory.CreateDbContextAsync();
|
||||||
if (_DataContext != null)
|
if (_DataContext != null)
|
||||||
{
|
{
|
||||||
SelectedCocktail = _DataContext.Cocktails.Include(c => c.Cocktailflaschen).ThenInclude(cf => cf.Flasche).Single(c => c.Id == id);
|
SelectedCocktail = _DataContext.Cocktails.Include(c => c.Cocktailflaschen).ThenInclude(cf => cf.Flasche).Single(c => c.Id == id);
|
||||||
|
ModifiedCocktail = _DataContext.Cocktails.Include(c => c.Cocktailflaschen).ThenInclude(cf => cf.Flasche).AsNoTracking().Single(c => c.Id == id);
|
||||||
MaschinenFiller = _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToList();
|
MaschinenFiller = _DataContext.Fillers.Include(f => f.Flasche).OrderBy(f => f.Pos).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (SelectedCocktail != null)
|
||||||
|
// {
|
||||||
|
// foreach (CocktailFlasche cf in SelectedCocktail.Cocktailflaschen)
|
||||||
|
// {
|
||||||
|
// ModifiedCocktailRecipe.Add(new CocktailFlasche() {
|
||||||
|
// Flasche = cf.Flasche,
|
||||||
|
// Menge = cf.Menge
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ZutatInMaschine(CocktailFlasche zutat)
|
||||||
|
{
|
||||||
|
return (MaschinenFiller != null && MaschinenFiller.Exists(f => f.Flasche == zutat.Flasche));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prüft, ob der Cocktail gesendet werden kann
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private bool IsValid()
|
||||||
|
{
|
||||||
|
ErrorMessage = null;
|
||||||
|
if (ModifiedCocktail == null || MaschinenFiller == null)
|
||||||
|
{
|
||||||
|
ErrorMessage = "Cocktail nicht gefunden.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ModifiedCocktail.Cocktailflaschen.Count == 0)
|
||||||
|
{
|
||||||
|
ErrorMessage = "Der Cocktail enthält keine Zutaten";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!ModifiedCocktail.Cocktailflaschen.All(cf => MaschinenFiller.Any(mf => mf.Flasche?.Id == cf.FlascheID)))
|
||||||
|
{
|
||||||
|
ErrorMessage = "Es sind nicht alle Zutaten in der Cocktailmaschine geladen!";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CreateCocktailCode()
|
||||||
|
{
|
||||||
|
CocktailCode = null;
|
||||||
|
if (!IsValid() || ModifiedCocktail == null || MaschinenFiller == null) return;
|
||||||
|
|
||||||
|
List<string> lines = new();
|
||||||
|
lines.Add("START");
|
||||||
|
|
||||||
|
@foreach (CocktailFlasche Zutat in ModifiedCocktail.Cocktailflaschen.OrderBy(f => f.Reihenfolge))
|
||||||
|
{
|
||||||
|
string line = "";
|
||||||
|
Filler Filler = MaschinenFiller.First(mf => mf.Flasche?.Id == Zutat.FlascheID);
|
||||||
|
if (Filler.Type == Filler.FillerType.Pump)
|
||||||
|
{
|
||||||
|
line = $"P{Filler.Pos}={Zutat.Menge}";
|
||||||
|
} else if (Filler.Type == Filler.FillerType.Pourer)
|
||||||
|
{
|
||||||
|
line = $"F{Filler.Pos}={Zutat.Menge}";
|
||||||
|
}
|
||||||
|
lines.Add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.Add("ZIEL");
|
||||||
|
CocktailCode = String.Join("\r\n", lines.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Setzt die Alkoholintensität
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="intensity">Zugabe/Abzug von Alkohol in Prozent</param>
|
||||||
|
private void SetIntensity(int intensity)
|
||||||
|
{
|
||||||
|
DrinkIntensity = intensity;
|
||||||
|
if (ModifiedCocktail != null && SelectedCocktail != null)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||||
|
{
|
||||||
|
int OriginalMenge = SelectedCocktail.Cocktailflaschen.First(scf => scf.FlascheID == cf.FlascheID).Menge;
|
||||||
|
if (cf.Flasche.Alkoholisch)
|
||||||
|
{
|
||||||
|
cf.Menge = OriginalMenge + (OriginalMenge * intensity / 100);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cf.Menge = OriginalMenge - (OriginalMenge * intensity / 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Durch das anteilige Umrechnen ändert sich die Gesamtmenge, daher passen wir die Mengen nochmal an
|
||||||
|
int AktGesMenge = ModifiedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||||
|
int OrigMenge = SelectedCocktail.Cocktailflaschen.Sum(cf => cf.Menge);
|
||||||
|
foreach (CocktailFlasche cf in ModifiedCocktail.Cocktailflaschen)
|
||||||
|
{
|
||||||
|
cf.Menge = (int)((float)cf.Menge / AktGesMenge * OrigMenge);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user