28 lines
1010 B
C#
28 lines
1010 B
C#
using ConstructorAppUI.Dtos.TeamDtos;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace ConstructorAppUI.ViewComponents.HomeComponents
|
|
{
|
|
public class _HomeTeamPartialComponent : ViewComponent
|
|
{
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly string? _apiBaseUrl;
|
|
|
|
public _HomeTeamPartialComponent(IHttpClientFactory httpClientFactory, IConfiguration configuration)
|
|
{
|
|
_httpClientFactory = httpClientFactory;
|
|
_apiBaseUrl = configuration["ApiSettings:BaseUrl"];
|
|
}
|
|
|
|
public async Task<IViewComponentResult> InvokeAsync()
|
|
{
|
|
var client = _httpClientFactory.CreateClient();
|
|
var responseMessage = await client.GetAsync($"{_apiBaseUrl}/api/Team");
|
|
var jsonData = await responseMessage.Content.ReadAsStringAsync();
|
|
var values = JsonConvert.DeserializeObject<List<ResultTeamDto>>(jsonData);
|
|
return View(values);
|
|
}
|
|
}
|
|
}
|