52 lines
1.0 KiB
C#
52 lines
1.0 KiB
C#
using HackerNet.Application;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace HackerNet.Web.Controllers;
|
|
|
|
public class LinksController : HackerController
|
|
{
|
|
private readonly LinkService _linkService;
|
|
|
|
public LinksController(LinkService linkService)
|
|
{
|
|
_linkService = linkService;
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Index()
|
|
{
|
|
return View(_linkService.GetPublishedLinks());
|
|
// return View(db.Links.ToArray());// retourne Link[]
|
|
// return View(_linkRepository.GetAll());// retourne Link[]
|
|
}
|
|
|
|
// TODO: Page de détail d'un lien
|
|
|
|
[HttpGet]
|
|
public IActionResult Detail(Guid id)
|
|
{
|
|
return View(_linkService.GetLinkDetail(id));
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult New()
|
|
{
|
|
return View(new PublishLinkCommand());
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult New(PublishLinkCommand cmd)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(cmd);
|
|
}
|
|
|
|
_linkService.PublishLink(cmd);
|
|
|
|
SetFlashMessage("Votre lien a correctement été publié !");
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
} |