yavsc/src/Yavsc/ViewComponents/CommentViewComponent.cs

21 lines
829 B
C#
Raw Normal View History

2017-10-04 23:53:47 +02:00
using Microsoft.AspNet.Mvc;
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];
return View(longCommentable.GetType().Name, new Comment{ PostId = longCommentable.Id });
}
}
2021-03-10 01:41:31 +00:00
}