CatherineLynwood/CatherineLynwood/Components/BlogCommentComponent.cs
2025-06-09 22:43:31 +01:00

36 lines
1.1 KiB
C#

using CatherineLynwood.Models;
using CatherineLynwood.Services;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace CatherineLynwood.Components
{
public class BlogCommentComponent : ViewComponent
{
private DataAccess _dataAccess;
public BlogCommentComponent(DataAccess dataAccess)
{
_dataAccess = dataAccess;
}
public async Task<IViewComponentResult> InvokeAsync(int blogID)
{
ViewData["VpnWarning"] = HttpContext.Items.ContainsKey("IsVpn") && (bool)HttpContext.Items["IsVpn"];
BlogComments blogComments = await _dataAccess.GetBlogCommentsAsync(blogID);
PreFillContact preFillContact = Request.Cookies["PreFill"] != null ? JsonConvert.DeserializeObject<PreFillContact>(Request.Cookies["PreFill"]) : new PreFillContact();
blogComments.Name = preFillContact.Name;
blogComments.EmailAddress = preFillContact.EmailAddress;
blogComments.Age = preFillContact.Age;
blogComments.Sex = preFillContact.Sex;
return View(blogComments);
}
}
}