yavsc/src/Yavsc/ViewComponents/CommentViewComponent.cs

21 lines
837 B
C#
Raw Normal View History

2023-03-19 17:57:55 +00:00
using Microsoft.AspNetCore.Mvc;
2017-10-04 23:53:47 +02:00
using Microsoft.Extensions.Localization;
using Yavsc.Models.Blog;
namespace Yavsc.ViewComponents
{
2019-06-17 20:52:51 +01:00
public partial class CommentViewComponent : ViewComponent
2017-10-04 23:53:47 +02:00
{
2021-03-10 01:41:31 +00:00
private readonly IStringLocalizer<CommentViewComponent> localizer;
2017-10-04 23:53:47 +02:00
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer)
{
2021-03-10 01:41:31 +00:00
this.localizer = localizer;
2017-10-04 23:53:47 +02:00
}
public IViewComponentResult Invoke(IIdentified<long> longCommentable)
{
2019-06-17 20:52:51 +01:00
// for a BlogPost, it results in the localization 'apiRouteCommentBlogPost': blogcomments
2017-10-04 23:53:47 +02:00
ViewData["apictlr"] = "/api/"+localizer["apiRouteComment"+longCommentable.GetType().Name];
2024-12-14 20:21:41 +00:00
return View(longCommentable.GetType().Name, new Comment{ ReceiverId = longCommentable.Id });
2017-10-04 23:53:47 +02:00
}
}
2021-03-10 01:41:31 +00:00
}