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