Ajout de la page de détail

This commit is contained in:
YuukanOO 2021-04-26 16:31:00 +02:00
parent 4954c68161
commit f15443be34
4 changed files with 25 additions and 3 deletions

View File

@ -50,6 +50,16 @@ namespace Application
// CommentsCount = 54,
// }).ToArray();
return LinksDTO().ToArray();
}
public LinkDTO GetLinkById(Guid id)
{
return LinksDTO().Single(link => link.Id == id);
}
private IQueryable<LinkDTO> LinksDTO()
{
return _data.Links
.Select(link => new LinkDTO
{
@ -61,8 +71,7 @@ namespace Application
CommentsCount = 54,
})
// .Where(linkDto => linkDto.UpvotesCount > 5)
.OrderByDescending(linkDto => linkDto.CreatedAt)
.ToArray();
.OrderByDescending(linkDto => linkDto.CreatedAt);
}
}
}

View File

@ -1,3 +1,4 @@
using System;
using Application;
using Microsoft.AspNetCore.Mvc;
@ -18,6 +19,12 @@ namespace Website
return View(_service.GetAllLinks());
}
[HttpGet("{controller}/detail/{linkId:guid}")]
public IActionResult Show(Guid linkId)
{
return View(_service.GetLinkById(linkId));
}
// [HttpGet] // Implicite car HttpGet par défaut
public IActionResult Create()
{

View File

@ -11,7 +11,7 @@
<ul>
@foreach (var link in Model)
{
<li>@link.Url - @link.CreatedAt</li>
<li>@link.Url - @link.CreatedAt - 🗨 @link.CommentsCount - <a asp-controller="Links" asp-action="Show" asp-route-linkId="@link.Id">Show</a></li>
}
</ul>
}

View File

@ -0,0 +1,6 @@
@model Application.LinkDTO
@{
ViewData["Title"] = $"Viewing link {Model.Url}";
}
<h1>Viewing link @Model.Url</h1>