34 lines
801 B
C#
34 lines
801 B
C#
using HN.Application;
|
|
using Website.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using MediatR;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Website.Controllers
|
|
{
|
|
public sealed class CommentsController : BaseController
|
|
{
|
|
private readonly IMediator _bus;
|
|
|
|
public CommentsController(IMediator bus)
|
|
{
|
|
_bus = bus;
|
|
}
|
|
|
|
[ValidateAntiForgeryToken]
|
|
[HttpPost]
|
|
public async Task<IActionResult> Create(CommentLinkCommand command)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View("../Links/Show", new ShowLinkViewModel(await _bus.Send(new GetLinkQuery(command.LinkId)), command));
|
|
}
|
|
|
|
await _bus.Send(command);
|
|
|
|
SetFlash("Comment added!");
|
|
|
|
return RedirectToAction(nameof(LinksController.Show), "Links", new { id = command.LinkId });
|
|
}
|
|
}
|
|
} |