TourIAm/TIAMWebApp/Shared/Services/ExchangeRateService.cs

36 lines
909 B
C#

using System.Net.Http;
using System.Net.Http.Json;
using System.Threading.Tasks;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide;
namespace TIAMWebApp.Shared.Application.Services
{
public class ExchangeRateService
{
private readonly HttpClient _httpClient;
public ExchangeRateService(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<ExchangeRate> GetExchangeRateAsync()
{
var url = $"{Setting.ApiBaseUrl}/{APIUrls.GetExchangeRate}";
return await _httpClient.GetFromJsonAsync<ExchangeRate>(url);
}
public async Task SetExchangeRateAsync(ExchangeRate rate)
{
var url = $"{Setting.ApiBaseUrl}/{APIUrls.UpdateExchangeRate}";
await _httpClient.PostAsJsonAsync(url, rate);
}
}
}