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