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