hn-dotnet/Apps/Website/Controllers/CommentsController.cs
2020-12-11 09:39:38 +01:00

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 });
}
}
}