47 lines
1.0 KiB
C#
47 lines
1.0 KiB
C#
using HackerNet.Application;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HackerNet.Web.Controllers;
|
|
|
|
public class CommentsController : HackerController
|
|
{
|
|
private readonly LinkService _linkService;
|
|
|
|
public CommentsController(LinkService linkService)
|
|
{
|
|
_linkService = linkService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult New(Guid id)
|
|
{
|
|
var link = _linkService.GetLinkDetail(id);
|
|
ViewData["LinkUrl"] = link.Url;
|
|
|
|
return View(new PublishCommentCommand
|
|
{
|
|
LinkId = id
|
|
});
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult New(PublishCommentCommand cmd)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
var link = _linkService.GetLinkDetail(cmd.LinkId);
|
|
ViewData["LinkUrl"] = link.Url;
|
|
return View(cmd);
|
|
}
|
|
|
|
_linkService.PublishComment(cmd);
|
|
|
|
SetFlashMessage("Votre commentaire a été publié !");
|
|
|
|
// asp-controller="Links" asp-action="Detail"
|
|
// asp-route-id="@Model.Id"
|
|
|
|
return RedirectToAction("Detail", "Links", new { id = cmd.LinkId });
|
|
}
|
|
} |