From 075d2a48387b546bf3b4921dcda62c563e2ad868 Mon Sep 17 00:00:00 2001 From: MET18937 <79221078+MET18937@users.noreply.github.com> Date: Fri, 23 Jun 2023 20:04:29 +0200 Subject: [PATCH] Update shoppingcart --- src/y4f/Pages/ShoppingCart.razor | 394 ++++++++++++++++++-------- src/y4f/wwwroot/css/shopping_cart.css | 11 +- 2 files changed, 285 insertions(+), 120 deletions(-) diff --git a/src/y4f/Pages/ShoppingCart.razor b/src/y4f/Pages/ShoppingCart.razor index cbd60aa..0046e0c 100644 --- a/src/y4f/Pages/ShoppingCart.razor +++ b/src/y4f/Pages/ShoppingCart.razor @@ -1,129 +1,293 @@ @page "/shopping_cart" - +@inject HttpClient Http +@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage +@inject NavigationManager _navigationManager Warenkorb

Warenkorb

-
-
+
+
-
-
- @*Tabelle Ihre Bestellung*@ -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ihre Bestellung
- 1 Nudel mit Hühnerfleisch (groß) -
mit Knoblauchsoße
-
9,10€
1 Coca Cola2,50€
Summe11,60€
+
+
+ @*Tabelle Ihre Bestellung*@ +
+ + + + + + + + + @if (menuitemIds.Count == 0) + { +
+
Warenkorb ist leer
+
+ } + else + { + @foreach (var item in menuitemIds) + { + @foreach (var item2 in menuitems) + { + @if (item.Key == item2.IdmenuItem) + { + - + + + + } + } + + } + } + + + + + + + +
Ihre Bestellung
+ @item.Value x + @item2.Bezeichnung + - -
-
- @*Essen Abholen?*@ -
-
-
-
- - - - - - - - - - - - -
- Wann wollen Sie Ihr Essen abholen? -
-
-
- - -   - Uhr -
-
-
-
-
-
-
- @*Buttons*@ -
-
-
- - -
-
-
-
-
- +
@item2.Zusatzinformation
+
@(item2.Preis * item.Value)€
Summe + @summe€ +
+ +
+ +
+
+
+ @*Essen Abholen?*@ +
+
+
+
+ + + + + + + + + + + + +
+ Wann wollen Sie Ihr Essen abholen? +
+
+
+ + +   + Uhr +
+
+
+
+
+
+
+ + @*Buttons*@ +
+
+
+ Zurück + Weiter +
+
+
+
+
+
+ + + + +@code { + public decimal summe; + public Dictionary menuitemIds = new Dictionary(); + + private void SetMenuItemId(int id) + { + if (menuitemIds.ContainsKey(id)) + { + menuitemIds[id]++; + } + else + { + menuitemIds.Add(id, 1); + } + localStorage.SetItem>("MenuItemIds", menuitemIds); + } + + + private void DelMenuItemId(int id) + { + if (menuitemIds.ContainsKey(id)) + { + if (menuitemIds[id] > 1) + { + menuitemIds[id]--; + } + else + { + menuitemIds.Remove(id); + } + } + localStorage.SetItem>("MenuItemIds", menuitemIds); + _navigationManager.NavigateTo(_navigationManager.Uri, forceLoad: true); + } + + + + // allergien, bestellungsposition, kunde, menuitem, menuitemkategorie, menuitemueberkategorie, rabatt + private List allergien = new List(); + private List bestellungspositions = new List(); + private List kunden = new List(); + private List menuitems = new List(); + private List menuitemkategories = new List(); + private List menuitemueberkategories = new List(); + private List rabatte = new List(); + + protected override async Task OnInitializedAsync() + { + // get data from localstorage + if (localStorage.GetItem>("MenuItemIds") != null) + { + menuitemIds = localStorage.GetItem>("MenuItemIds"); + } + + // get data from api + allergien = await Http.GetFromJsonAsync>("https://localhost:7076/api/allergien"); + bestellungspositions = await Http.GetFromJsonAsync>("https://localhost:7076/api/bestellungspositionen"); + kunden = await Http.GetFromJsonAsync>("https://localhost:7076/api/kunden"); + menuitems = await Http.GetFromJsonAsync>("https://localhost:7076/api/Menuitems"); + menuitemkategories = await Http.GetFromJsonAsync>("https://localhost:7076/api/Menuitemkategories"); + menuitemueberkategories = await Http.GetFromJsonAsync>("https://localhost:7076/api/Menuitemueberkategories"); + rabatte = await Http.GetFromJsonAsync>("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 MenuItemIdmenuItems { get; set; } = new List(); + } + 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 MenuItemIdmenuItems { get; set; } = new List(); + } + public class Kunde + { + public int Idkunde { get; set; } + + public string? Code { get; set; } + + public int? Treuepunkte { get; set; } + + public virtual ICollection Bestellungspositions { get; set; } = new List(); + } + + 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 AllergieIdallergies { get; set; } = new List(); + + public virtual ICollection BestellungspositionIdbestellungs { get; set; } = new List(); + } + 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 Menuitems { get; set; } = new List(); + } + + public class Menuitemueberkategorie + { + public int IdmenuItemUeberkategorie { get; set; } + + public string? Bezeichnung { get; set; } + + public virtual ICollection Menuitemkategories { get; set; } = new List(); + } + + 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 Bestellungspositions { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/src/y4f/wwwroot/css/shopping_cart.css b/src/y4f/wwwroot/css/shopping_cart.css index fe6a336..2a35e43 100644 --- a/src/y4f/wwwroot/css/shopping_cart.css +++ b/src/y4f/wwwroot/css/shopping_cart.css @@ -11,6 +11,7 @@ border-radius: 17px; overflow: hidden; border-color: #C7FFD5; + border-width: 0px; } .bg_lightgreen { @@ -23,19 +24,19 @@ border-bottom-width: 0; } -.btn_back { +.btn_bg { background-color: #F9BE89; /*width: 60%;*/ margin-bottom: 13px; border-radius: 30px; - height: 50px; - border: 0px; + /*height: 50px;*/ + /*border: 0px;*/ } .btn_forward { background-color: #89F9A5; /*width: 60%;*/ border-radius: 30px; - height: 50px; - border: 0px; + /*height: 50px;*/ + /*border: 0px;*/ }