34 lines
973 B
C#
34 lines
973 B
C#
using PruebaAzureAD.Models;
|
|
using System.Text.Json;
|
|
using System;
|
|
|
|
namespace PruebaAzureAD.Servicios
|
|
{
|
|
public class Estado
|
|
{
|
|
readonly string url = "http://localhost:46647/api/";
|
|
|
|
public async Task<List<EstadoViewModel>?> ObtenerEstados()
|
|
{
|
|
List<EstadoViewModel>? estados = new List<EstadoViewModel>();
|
|
|
|
try
|
|
{
|
|
using (var httpClient = new HttpClient())
|
|
{
|
|
var respuesta = await httpClient.GetAsync(url + "Estado");
|
|
var respuestaString = await respuesta.Content.ReadAsStringAsync();
|
|
estados = JsonSerializer.Deserialize<List<EstadoViewModel>>(respuestaString,
|
|
new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
|
|
throw;
|
|
}
|
|
|
|
return estados;
|
|
}
|
|
}
|
|
}
|