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