Files
constructdemo/ConstructorAppUI/ViewComponents/HomeComponents/_HomeAboutPartialComponent.cs
2025-05-01 15:18:30 +03:00

27 lines
1020 B
C#

using ConstructorAppUI.Dtos.ServiceDtos;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace ConstructorAppUI.ViewComponents.HomeComponents
{
public class _HomeAboutPartialComponent : ViewComponent
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly string? _apiBaseUrl;
public _HomeAboutPartialComponent(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/Service");
var jsonData = await responseMessage.Content.ReadAsStringAsync();
var values = JsonConvert.DeserializeObject<List<ResultServiceDto>>(jsonData);
return View(values);
}
}
}