Code: Select all
Home.cs
Code: Select all
@page "/"
@using sexy.Components.Shared
@using sexy.Models
Home
Search Flights
@if (!string.IsNullOrEmpty(testMessage))
{
@testMessage
}
@if (flights != null && flights.Count > 0)
{
Flights:
[list]
@foreach (var item in flights)
{
[*]
@item.Origin to @item.Destination, Departure: @item.DepartureDate, Return: @item.ReturnDate, Price: @item.Price, Airlines: @string.Join(", ", item.Airlines)
}
[/list]
}
< /code>
Home.razor.cs
Code: Select all
using Microsoft.AspNetCore.Components;
using sexy.Models;
using sexy.Components.Shared;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace sexy.Components.Pages
{
public partial class Home : ComponentBase
{
[Inject] public TravelAPI TravelAPI { get; set; }
public List flights = new();
public string testMessage = "";
public string origin { get; set; }
public string destination { get; set; }
protected async Task LoadFlights()
{
if (string.IsNullOrWhiteSpace(origin) || string.IsNullOrWhiteSpace(destination))
{
testMessage = "Please enter both origin and destination.";
flights.Clear();
return;
}
try
{
var token = await TravelAPI.ConnectOAuth();
flights = await TravelAPI.GetFlights(token, "MEL", "SYD");
testMessage = $"Loaded {flights.Count} flights.";
}
catch (Exception ex)
{
testMessage = $"Error: {ex.Message}";
flights.Clear();
}
}
}
}
< /code>
I have tried adding the method within the razor file itself (within a @code block), and the breakpoint withint LoadFlights()