yavsc/src/Yavsc/ViewComponents/CommentViewComponent.cs

35 lines
1.1 KiB
C#
Raw Normal View History

2024-12-15 20:48:04 +00:00
using System.Diagnostics;
2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
2024-12-15 20:48:04 +00:00
using Microsoft.EntityFrameworkCore;
2017-10-04 23:53:47 +02:00
using Microsoft.Extensions.Localization;
2024-12-15 20:48:04 +00:00
using Yavsc.Models;
2017-10-04 23:53:47 +02:00
using Yavsc.Models.Blog;
namespace Yavsc.ViewComponents
{
2024-12-15 20:48:04 +00:00
public class CommentViewComponent : ViewComponent
2017-10-04 23:53:47 +02:00
{
2024-12-15 20:48:04 +00:00
private readonly ApplicationDbContext context;
2021-03-10 01:41:31 +00:00
private readonly IStringLocalizer<CommentViewComponent> localizer;
2024-12-15 20:48:04 +00:00
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer,
ApplicationDbContext context
)
2017-10-04 23:53:47 +02:00
{
2024-12-15 20:48:04 +00:00
this.context = context;
2021-03-10 01:41:31 +00:00
this.localizer = localizer;
2017-10-04 23:53:47 +02:00
}
2024-12-15 20:48:04 +00:00
public async Task<IViewComponentResult> InvokeAsync(long id)
2017-10-04 23:53:47 +02:00
{
2024-12-15 20:48:04 +00:00
var comment = await context.Comment.Include(c=>c.Children).FirstOrDefaultAsync(c => c.Id==id);
if (comment == null)
throw new InvalidOperationException();
ViewData["apictlr"] = "/api/blogcomments";
return View("Default", comment);
}
private string GetDebuggerDisplay()
{
return ToString();
2017-10-04 23:53:47 +02:00
}
}
2021-03-10 01:41:31 +00:00
}