From f15443be342c110d4e298f218855e7c22e949068 Mon Sep 17 00:00:00 2001 From: YuukanOO Date: Mon, 26 Apr 2021 16:31:00 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20la=20page=20de=20d=C3=A9tail?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/LinkService.cs | 13 +++++++++++-- Apps/Website/Controllers/LinksController.cs | 7 +++++++ Apps/Website/Views/Links/Index.cshtml | 2 +- Apps/Website/Views/Links/Show.cshtml | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 Apps/Website/Views/Links/Show.cshtml diff --git a/Application/LinkService.cs b/Application/LinkService.cs index 7af9e0c..5d080bf 100644 --- a/Application/LinkService.cs +++ b/Application/LinkService.cs @@ -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 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); } } } diff --git a/Apps/Website/Controllers/LinksController.cs b/Apps/Website/Controllers/LinksController.cs index 4c0d6e6..97a7fd3 100644 --- a/Apps/Website/Controllers/LinksController.cs +++ b/Apps/Website/Controllers/LinksController.cs @@ -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() { diff --git a/Apps/Website/Views/Links/Index.cshtml b/Apps/Website/Views/Links/Index.cshtml index 9c2af1f..eb10f0c 100644 --- a/Apps/Website/Views/Links/Index.cshtml +++ b/Apps/Website/Views/Links/Index.cshtml @@ -11,7 +11,7 @@ } \ No newline at end of file diff --git a/Apps/Website/Views/Links/Show.cshtml b/Apps/Website/Views/Links/Show.cshtml new file mode 100644 index 0000000..d9d491a --- /dev/null +++ b/Apps/Website/Views/Links/Show.cshtml @@ -0,0 +1,6 @@ +@model Application.LinkDTO +@{ + ViewData["Title"] = $"Viewing link {Model.Url}"; +} + +

Viewing link @Model.Url