TFS_ANTIGUO/TPAtesa_RecHuma/PruebaAzureAD/Servicios/Pais.cs
2026-06-26 10:14:39 -06:00

34 lines
957 B
C#

using PruebaAzureAD.Models;
using System.Text.Json;
using System;
namespace PruebaAzureAD.Servicios
{
public class Pais
{
readonly string url = "http://localhost:46647/api/";
public async Task<List<PaisViewModel>?> ObtenerPaises()
{
List<PaisViewModel>? paises = new List<PaisViewModel>();
try
{
using (var httpClient = new HttpClient())
{
var respuesta = await httpClient.GetAsync(url + "Pais");
var respuestaString = await respuesta.Content.ReadAsStringAsync();
paises = JsonSerializer.Deserialize<List<PaisViewModel>>(respuestaString,
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
}
}
catch (Exception)
{
throw;
}
return paises;
}
}
}