using Microsoft.AspNetCore.Mvc; using HN.Application; using MediatR; using System.Threading.Tasks; namespace Website.Controllers { public class LinksController : BaseController { private readonly IMediator _bus; public LinksController(IMediator bus) { _bus = bus; } public async Task Index() { return View(await _bus.Send(new ListLinksQuery())); } public IActionResult Create() { return View(new AddLinkCommand()); } [HttpPost] [ValidateAntiForgeryToken] public async Task Create(AddLinkCommand command) { if (!ModelState.IsValid) { return View(command); } await _bus.Send(command); SetFlash("Link added!"); return RedirectToAction(nameof(Index)); } } }