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

49 lines
1.8 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using ConstructorAppUI.Dtos.FooterDtos;
using ConstructorAppUI.Dtos.HomeBannerDtos;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace ConstructorAppUI.ViewComponents.HomeLayoutComponents
{
public class _HomeLayoutNavbarPartialComponent : ViewComponent
{
private readonly IHttpClientFactory _httpClientFactory;
private readonly string? _apiBaseUrl;
public _HomeLayoutNavbarPartialComponent(IHttpClientFactory httpClientFactory, IConfiguration configuration)
{
_httpClientFactory = httpClientFactory;
_apiBaseUrl = configuration["ApiSettings:BaseUrl"];
}
public async Task<IViewComponentResult> InvokeAsync()
{
var client = _httpClientFactory.CreateClient();
// HomeBanner verisi çekiliyor
var responseMessage = await client.GetAsync($"{_apiBaseUrl}/api/HomeBanner");
var values = new List<ResultHomeBannerDto>();
if (responseMessage.IsSuccessStatusCode)
{
var jsonData = await responseMessage.Content.ReadAsStringAsync();
values = JsonConvert.DeserializeObject<List<ResultHomeBannerDto>>(jsonData);
}
// Footer verisi çekiliyor (telefon numarası için)
var footerResponse = await client.GetAsync($"{_apiBaseUrl}/api/Footer");
if (footerResponse.IsSuccessStatusCode)
{
var jsonFooter = await footerResponse.Content.ReadAsStringAsync();
var footerData = JsonConvert.DeserializeObject<List<ResultFooterDto>>(jsonFooter);
var phone = footerData.FirstOrDefault()?.Phone;
ViewBag.FooterPhone = phone;
}
return View(values);
}
}
}