41 lines
783 B
C#
41 lines
783 B
C#
using Microsoft.AspNetCore.Mvc;
|
|
using HN.Application;
|
|
using MediatR;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Website.Controllers
|
|
{
|
|
public class LinksController : Controller
|
|
{
|
|
private readonly IMediator _bus;
|
|
|
|
public LinksController(IMediator bus)
|
|
{
|
|
_bus = bus;
|
|
}
|
|
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
return View(await _bus.Send(new ListLinksQuery()));
|
|
}
|
|
|
|
public IActionResult Create()
|
|
{
|
|
return View(new AddLinkCommand());
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Create(AddLinkCommand command)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(command);
|
|
}
|
|
|
|
await _bus.Send(command);
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
}
|
|
} |