Files
ARM64/eNavigator/eNavigatorUI/Pages/Weather.razor.cs
2025-04-03 17:28:36 -04:00

40 lines
1.1 KiB
C#

using System.Net.Http.Json;
using eNavigator.Routes;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
namespace eNavigator.Pages
{
public partial class Weather
{
[Inject]
private NavigationManager NavigationManager { get; set; } = default!;
[Inject]
private AuthenticationStateProvider authenticationStateProvider { get; set; } = default;
public WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
AuthenticationState authenticationState = await authenticationStateProvider.GetAuthenticationStateAsync();
if(!authenticationState.User.Identity.IsAuthenticated)
{
NavigationManager.NavigateTo(PageRoute.Login);
}
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}
public class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
}