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