58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using System;
|
|
using Application;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Website.Models;
|
|
|
|
namespace Website
|
|
{
|
|
public class LinksController : BaseController
|
|
{
|
|
private readonly LinkService _linkService;
|
|
private readonly CommentService _commentService;
|
|
|
|
public LinksController(LinkService linkService, CommentService commentService)
|
|
{
|
|
_linkService = linkService;
|
|
_commentService = commentService;
|
|
}
|
|
|
|
public IActionResult Index()
|
|
{
|
|
// return Forbid();
|
|
return View(_linkService.GetAllLinks());
|
|
}
|
|
|
|
[HttpGet("{controller}/detail/{linkId:guid}")]
|
|
public IActionResult Show(Guid linkId)
|
|
{
|
|
// ViewData["Comments"] = _commentService.GetAllLinkComments(linkId);
|
|
|
|
return View(new ShowLinkViewModel(
|
|
_linkService.GetLinkById(linkId),
|
|
_commentService.GetAllLinkComments(linkId)));
|
|
}
|
|
|
|
// [HttpGet] // Implicite car HttpGet par défaut
|
|
public IActionResult Create()
|
|
{
|
|
// ViewData["Message"] = "Une valeur";
|
|
return View();
|
|
}
|
|
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public IActionResult Create(PublishLinkCommand cmd)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(cmd);
|
|
}
|
|
|
|
_linkService.PublishLink(cmd);
|
|
|
|
Success("Your link was posted!");
|
|
|
|
return RedirectToAction(nameof(Index));
|
|
}
|
|
}
|
|
} |