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