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

43 lines
1.3 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 FetchServiceShopOrders
{
[Inject] protected HttpClient? HttpClient { get; set; }
[Inject] protected ILogger<FetchServiceShopOrders>? Logger { get; set; }
private ServiceShopOrder[]? _ServiceShopOrders;
//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(IServiceShopOrderController<object>.Action.All);
string controllerName = IServiceShopOrderController<object>.GetRouteName();
try
{ _ServiceShopOrders = await HttpClient.GetFromJsonAsync<ServiceShopOrder[]>($"api/{controllerName}/{actionName}"); }
catch (Exception)
{
string json = await HttpClient.GetStringAsync($"api/{controllerName}/{actionName}");
Logger.LogInformation(message: json);
}
}
}