Add visibility if valid kunde on speisekarte

This commit is contained in:
MET18937 2023-06-24 17:23:41 +02:00
parent a9418aea33
commit d45fa68fe0
2 changed files with 29 additions and 0 deletions

View File

@ -3,6 +3,7 @@
@inject HttpClient Http @inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage @inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<PageTitle>Yummy4Friends</PageTitle> <PageTitle>Yummy4Friends</PageTitle>
@ -35,6 +36,7 @@
if (kunde.Code == qrcodeValue) if (kunde.Code == qrcodeValue)
{ {
localStorage.SetItem("kunde", kunde); localStorage.SetItem("kunde", kunde);
_navigationManager.NavigateTo("/speisekarte");
break; break;
} }
} }

View File

@ -1,6 +1,8 @@
@page "/Speisekarte" @page "/Speisekarte"
@inject HttpClient Http @inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<h1>Speisekarte</h1> <h1>Speisekarte</h1>
<div class="row justify-content-center"> <div class="row justify-content-center">
@ -72,11 +74,29 @@
@code { @code {
private List<Menuitemkategorie> menuitemkategories = new List<Menuitemkategorie>(); private List<Menuitemkategorie> menuitemkategories = new List<Menuitemkategorie>();
private List<Menuitemueberkategorie> menuitemueberkategories = new List<Menuitemueberkategorie>(); private List<Menuitemueberkategorie> menuitemueberkategories = new List<Menuitemueberkategorie>();
private List<Kunde> kunden = new List<Kunde>();
private Kunde curretKunde = new Kunde();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
if (kunden.Count > 0)
{
var kunde = localStorage.GetItem<Kunde>("kunde");
if (kunde != null)
{
curretKunde = kunde;
}
else
{
_navigationManager.NavigateTo("/");
}
}
menuitemkategories = await Http.GetFromJsonAsync<List<Menuitemkategorie>>("https://localhost:7076/api/MenuItemKategories"); menuitemkategories = await Http.GetFromJsonAsync<List<Menuitemkategorie>>("https://localhost:7076/api/MenuItemKategories");
menuitemueberkategories = await Http.GetFromJsonAsync<List<Menuitemueberkategorie>>("https://localhost:7076/api/MenuItemUeberkategories"); menuitemueberkategories = await Http.GetFromJsonAsync<List<Menuitemueberkategorie>>("https://localhost:7076/api/MenuItemUeberkategories");
} }
public class Menuitemkategorie public class Menuitemkategorie
@ -97,4 +117,11 @@
} }
public class Kunde
{
public int Idkunde { get; set; }
public string Code { get; set; }
public int Treuepunkte { get; set; }
}
} }