This repository has been archived on 2022-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
DevOpsOpenHack/support/tripviewer/web/Models/Stores/TripStore.cs

44 lines
1.3 KiB
C#
Raw Permalink Normal View History

2022-11-03 20:41:13 +00:00
namespace Simulator.DataStore.Stores
{
using Simulator.DataObjects;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
public class TripStore : BaseStore//, IBaseStore<Trip>
{
public TripStore(IHttpClientFactory clientFactory, string EndPoint) : base(clientFactory)
{
base.InitializeStore(EndPoint);
}
public async Task<Trip> GetItemAsync(string id)
{
Trip trip = null;
HttpResponseMessage response = await Client.GetAsync($"/api/trips/{id}");
if (response.IsSuccessStatusCode)
{
response.Content.Headers.ContentType.MediaType = "application/json";
trip = await response.Content.ReadAsAsync<Trip>();
}
return trip;
}
public async Task<List<Trip>> GetItemsAsync()
{
List<Trip> trips = null;
HttpResponseMessage response = await Client.GetAsync("api/trips/");
if (response.IsSuccessStatusCode)
{
response.Content.Headers.ContentType.MediaType = "application/json";
trips = await response.Content.ReadAsAsync<List<Trip>>();
}
return trips;
}
}
}