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