Update shoppingcart

This commit is contained in:
MET18937 2023-06-23 20:04:29 +02:00
parent 04a221f20b
commit 075d2a4838
2 changed files with 285 additions and 120 deletions

View File

@ -1,129 +1,293 @@
@page "/shopping_cart" @page "/shopping_cart"
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<PageTitle>Warenkorb</PageTitle> <PageTitle>Warenkorb</PageTitle>
<h1>Warenkorb</h1> <h1>Warenkorb</h1>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-sm-12 col-lg-6"> <div class="col-sm-12 col-lg-6">
@*Tabelle Ihre Bestellung*@ @*Tabelle Ihre Bestellung*@
<div class="tbl-container"> <div class="tbl-container">
<table class="table bdr"> <table class="table bdr">
<thead class="bg_green"> <thead class="bg_green">
<tr> <tr>
<td>Ihre Bestellung</td> <td>Ihre Bestellung</td>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
<tbody class="bg_lightgreen"> <tbody class="bg_lightgreen">
<tr> @if (menuitemIds.Count == 0)
<td class="br" style="padding-top:20px; padding-bottom:0px; border-bottom-width: 0px;"> {
1 Nudel mit Hühnerfleisch (groß) <div class="card-body">
<div style="font-size:0.7rem;padding-left:15px;">mit Knoblauchsoße</div> <h5 class="card-title" style="font-size:10pt; margin-bottom:0px;">Warenkorb ist leer</h5>
</td> </div>
<td class="d-flex justify-content-center align-items-center" style="padding-top:20px; padding-bottom:0px;">9,10€</td> }
</tr> else
<tr> {
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;">1 Coca Cola</td> @foreach (var item in menuitemIds)
<td class="d-flex justify-content-center align-items-center" style="padding-top:0px;">2,50€</td> {
</tr> @foreach (var item2 in menuitems)
<tr> {
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td> @if (item.Key == item2.IdmenuItem)
<td class="d-flex justify-content-center align-items-center"></td> {
</tr> <tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px;"></td>
</tr>
</tbody>
<tfoot class="bg_lightgreen">
<tr style="border-top:solid 1px black;">
<th class="" style="text-align:right;">Summe</th>
<td class="d-flex justify-content-center align-items-center">11,60€</td>
</tr>
</tfoot>
</table>
</div> <td class="br" style="padding-top:20px; padding-bottom:0px; border-bottom-width: 0px;">
@item.Value x
@item2.Bezeichnung
<button @onclick="@(() => DelMenuItemId(item.Key))" class="btn btn-danger">del</button>
</div>
<div class="col-sm-12 col-lg-6">
<div class="h-100">
@*Essen Abholen?*@
<div class="row h-25 w-100">
<div class="col">
<div class="d-flex flex-column align-items-center ">
<div class="tbl-container bdr w-100">
<!-- <== overflow: hidden applied to parent -->
<table class="table bdr" cellspacing="0" cellpadding="0">
<thead class="bg_green">
<tr>
<td class="d-flex justify-content-center align-items-center" style="border-bottom:0px;">
Wann wollen Sie Ihr Essen abholen?
</td>
</tr>
</thead>
<tbody class="bg_lightgreen">
<tr>
<td class="d-flex justify-content-center align-items-center" style="padding-top:0px;">
<div style="margin:20px;">
<div class="d-flex justify-content-center align-items-center">
<input type="number" style="width:80px" min="10" max="20" />
<input type="number" style="width:80px" min="0" max="59" />
&nbsp;
Uhr
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
@*Buttons*@ <div style="font-size:0.7rem;padding-left:15px;">@item2.Zusatzinformation</div>
<div class="row h-75 w-100"> </td>
<div class="col mt-auto"> <td class="d-flex justify-content-center align-items-center" style="padding-top:20px; border-bottom-width:0px;">@(item2.Preis * item.Value)€</td>
<div class="d-flex flex-column align-items-center "> </tr>
<button class="btn_back w-75">Zurück</button> }
<button class="btn_forward w-75">Weiter</button> }
</div>
</div> }
</div> }
</div> </tbody>
</div> <tfoot class="bg_lightgreen">
</div> <tr style="border-top:solid 1px black;">
<th class="" style="text-align:right;">Summe</th>
<td class="d-flex justify-content-center align-items-center">
@summe€
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="col-sm-12 col-lg-6">
<div class="h-100">
@*Essen Abholen?*@
<div class="row h-25 w-100 ">
<div class="col">
<div class="d-flex flex-column align-items-center ">
<div class="tbl-container bdr w-100">
<!-- <== overflow: hidden applied to parent -->
<table class="table bdr" cellspacing="0" cellpadding="0">
<thead class="bg_green">
<tr>
<td class="d-flex justify-content-center align-items-center" style="border-bottom:0px;">
Wann wollen Sie Ihr Essen abholen?
</td>
</tr>
</thead>
<tbody class="bg_lightgreen">
<tr>
<td class="d-flex justify-content-center align-items-center" style="padding-top:0px;">
<div style="margin:20px;">
<div class="d-flex justify-content-center align-items-center">
<input type="number" style="width:80px" min="10" max="20" />
<input type="number" style="width:80px" min="0" max="59" />
&nbsp;
Uhr
</div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
@*Buttons*@
<div class="row h-75 w-100">
<div class="col mt-auto ">
<div class="d-flex flex-column align-items-center ">
<a href="/speisekarte" class="btn_bg w-75 btn text-center">Zurück</a>
<a href="#" class="btn_forward btn w-75 ">Weiter</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div> </div>
@code {
public decimal summe;
public Dictionary<int, int> menuitemIds = new Dictionary<int, int>();
private void SetMenuItemId(int id)
{
if (menuitemIds.ContainsKey(id))
{
menuitemIds[id]++;
}
else
{
menuitemIds.Add(id, 1);
}
localStorage.SetItem<Dictionary<int, int>>("MenuItemIds", menuitemIds);
}
private void DelMenuItemId(int id)
{
if (menuitemIds.ContainsKey(id))
{
if (menuitemIds[id] > 1)
{
menuitemIds[id]--;
}
else
{
menuitemIds.Remove(id);
}
}
localStorage.SetItem<Dictionary<int, int>>("MenuItemIds", menuitemIds);
_navigationManager.NavigateTo(_navigationManager.Uri, forceLoad: true);
}
// allergien, bestellungsposition, kunde, menuitem, menuitemkategorie, menuitemueberkategorie, rabatt
private List<Allergie> allergien = new List<Allergie>();
private List<Bestellungsposition> bestellungspositions = new List<Bestellungsposition>();
private List<Kunde> kunden = new List<Kunde>();
private List<Menuitem> menuitems = new List<Menuitem>();
private List<Menuitemkategorie> menuitemkategories = new List<Menuitemkategorie>();
private List<Menuitemueberkategorie> menuitemueberkategories = new List<Menuitemueberkategorie>();
private List<Rabatt> rabatte = new List<Rabatt>();
protected override async Task OnInitializedAsync()
{
// get data from localstorage
if (localStorage.GetItem<Dictionary<int, int>>("MenuItemIds") != null)
{
menuitemIds = localStorage.GetItem<Dictionary<int, int>>("MenuItemIds");
}
// get data from api
allergien = await Http.GetFromJsonAsync<List<Allergie>>("https://localhost:7076/api/allergien");
bestellungspositions = await Http.GetFromJsonAsync<List<Bestellungsposition>>("https://localhost:7076/api/bestellungspositionen");
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
menuitems = await Http.GetFromJsonAsync<List<Menuitem>>("https://localhost:7076/api/Menuitems");
menuitemkategories = await Http.GetFromJsonAsync<List<Menuitemkategorie>>("https://localhost:7076/api/Menuitemkategories");
menuitemueberkategories = await Http.GetFromJsonAsync<List<Menuitemueberkategorie>>("https://localhost:7076/api/Menuitemueberkategories");
rabatte = await Http.GetFromJsonAsync<List<Rabatt>>("https://localhost:7076/api/Rabatte");
// calculate the sum of all menuitems
summe = 0;
foreach (var item in menuitemIds)
{
foreach (var item2 in menuitems)
{
if (item.Key == item2.IdmenuItem)
{
summe += item2.Preis * item.Value;
}
}
}
}
public class Allergie
{
public int Idallergie { get; set; }
public string? Beschreibung { get; set; }
public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
}
public class Bestellungsposition
{
public int Idbestellung { get; set; }
public int? Menge { get; set; }
public DateTime? Datum { get; set; }
public int KundeIdkunde { get; set; }
public int RabattIdrabatt { get; set; }
public virtual Kunde KundeIdkundeNavigation { get; set; } = null!;
public virtual Rabatt RabattIdrabattNavigation { get; set; } = null!;
public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
}
public class Kunde
{
public int Idkunde { get; set; }
public string? Code { get; set; }
public int? Treuepunkte { get; set; }
public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
}
public class Menuitem
{
public int IdmenuItem { get; set; }
public string? Bezeichnung { get; set; }
public string? Zusatzinformation { get; set; }
public decimal Preis { get; set; }
public int MenuItemKategorieIdmenuItemKategorie { get; set; }
public virtual Menuitemkategorie MenuItemKategorieIdmenuItemKategorieNavigation { get; set; } = null!;
public virtual ICollection<Allergie> AllergieIdallergies { get; set; } = new List<Allergie>();
public virtual ICollection<Bestellungsposition> BestellungspositionIdbestellungs { get; set; } = new List<Bestellungsposition>();
}
public class Menuitemkategorie
{
public int IdmenuItemKategorie { get; set; }
public string? Bezeichnung { get; set; }
public int MenuItemUeberkategorieIdmenuItemUeberkategorie { get; set; }
public virtual Menuitemueberkategorie MenuItemUeberkategorieIdmenuItemUeberkategorieNavigation { get; set; } = null!;
public virtual ICollection<Menuitem> Menuitems { get; set; } = new List<Menuitem>();
}
public class Menuitemueberkategorie
{
public int IdmenuItemUeberkategorie { get; set; }
public string? Bezeichnung { get; set; }
public virtual ICollection<Menuitemkategorie> Menuitemkategories { get; set; } = new List<Menuitemkategorie>();
}
public class Rabatt
{
public int Idrabatt { get; set; }
public decimal? Prozent { get; set; }
public DateTime? GueltigkeitVon { get; set; }
public DateTime? GueltigkeitBis { get; set; }
public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
}
}

View File

@ -11,6 +11,7 @@
border-radius: 17px; border-radius: 17px;
overflow: hidden; overflow: hidden;
border-color: #C7FFD5; border-color: #C7FFD5;
border-width: 0px;
} }
.bg_lightgreen { .bg_lightgreen {
@ -23,19 +24,19 @@
border-bottom-width: 0; border-bottom-width: 0;
} }
.btn_back { .btn_bg {
background-color: #F9BE89; background-color: #F9BE89;
/*width: 60%;*/ /*width: 60%;*/
margin-bottom: 13px; margin-bottom: 13px;
border-radius: 30px; border-radius: 30px;
height: 50px; /*height: 50px;*/
border: 0px; /*border: 0px;*/
} }
.btn_forward { .btn_forward {
background-color: #89F9A5; background-color: #89F9A5;
/*width: 60%;*/ /*width: 60%;*/
border-radius: 30px; border-radius: 30px;
height: 50px; /*height: 50px;*/
border: 0px; /*border: 0px;*/
} }