yavsc/src/Yavsc/ViewComponents/CommentViewComponent.cs

22 lines
822 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
{
IStringLocalizer<CommentViewComponent> localizer;
public CommentViewComponent(IStringLocalizer<CommentViewComponent> localizer)
{
this.localizer = localizer;
2019-06-17 20:52:51 +01:00
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 });
}
}
}