expose-myit/Client/Pages/FetchSsaOrders.razor.cs

43 lines
1.2 KiB
C#

using Expose.MyIT.Shared.Models.Stateless;
using Expose.MyIT.Shared.ViewModels;
using Microsoft.AspNetCore.Components;
using System.Net.Http.Json;
namespace Expose.MyIT.Client.Pages;
public partial class FetchSsaOrders
{
[Inject] protected HttpClient? HttpClient { get; set; }
[Inject] protected ILogger<Counter>? Logger { get; set; }
private SsaOrder[]? _SsaOrders;
//Id
//Name
//BookingNames
//Type
//State
//ItemNumber
//CreatedDate
//DecidedDate
//Recipient
//Requestor
protected override async Task OnInitializedAsync()
{
if (Logger is null)
throw new NullReferenceException(nameof(Logger));
if (HttpClient is null)
throw new NullReferenceException(nameof(HttpClient));
string actionName = nameof(ISsaOrderController<object>.Action.All);
string controllerName = ISsaOrderController<object>.GetRouteName();
try
{ _SsaOrders = await HttpClient.GetFromJsonAsync<SsaOrder[]>($"api/{controllerName}/{actionName}"); }
catch (Exception)
{
string json = await HttpClient.GetStringAsync($"api/{controllerName}/{actionName}");
Logger.LogInformation(message: json);
}
}
}