Ajout des messages flash + vues partielles
This commit is contained in:
parent
f15443be34
commit
18473a0174
18
Apps/Website/Controllers/BaseController.cs
Normal file
18
Apps/Website/Controllers/BaseController.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace Website
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Classe abstraite de base pour tous nos controlleurs permettant d'exposer
|
||||||
|
/// 2 - 3 méthodes helpers.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class BaseController : Controller
|
||||||
|
{
|
||||||
|
public const string FlashMessageKey = "FlashMessage";
|
||||||
|
|
||||||
|
protected void Success(string message)
|
||||||
|
{
|
||||||
|
TempData[FlashMessageKey] = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
|
|
||||||
namespace Website
|
namespace Website
|
||||||
{
|
{
|
||||||
public class LinksController : Controller
|
public class LinksController : BaseController
|
||||||
{
|
{
|
||||||
private readonly LinkService _service;
|
private readonly LinkService _service;
|
||||||
|
|
||||||
@ -43,6 +43,8 @@ namespace Website
|
|||||||
|
|
||||||
_service.PublishLink(cmd);
|
_service.PublishLink(cmd);
|
||||||
|
|
||||||
|
Success("Your link was posted!");
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,9 @@
|
|||||||
<ul>
|
<ul>
|
||||||
@foreach (var link in Model)
|
@foreach (var link in Model)
|
||||||
{
|
{
|
||||||
<li>@link.Url - @link.CreatedAt - 🗨 @link.CommentsCount - <a asp-controller="Links" asp-action="Show" asp-route-linkId="@link.Id">Show</a></li>
|
<li>
|
||||||
|
<partial name="_LinkItem" model="@link" />
|
||||||
|
</li>
|
||||||
}
|
}
|
||||||
</ul>
|
</ul>
|
||||||
}
|
}
|
||||||
@ -4,3 +4,5 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<h1>Viewing link @Model.Url</h1>
|
<h1>Viewing link @Model.Url</h1>
|
||||||
|
|
||||||
|
@* <partial name="_LinkItem" model="@Model" /> *@
|
||||||
8
Apps/Website/Views/Shared/_FlashMessage.cshtml
Normal file
8
Apps/Website/Views/Shared/_FlashMessage.cshtml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
@{
|
||||||
|
var text = (string)TempData[BaseController.FlashMessageKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
@if(!string.IsNullOrWhiteSpace(text))
|
||||||
|
{
|
||||||
|
<p class="alert alert-success">@text</p>
|
||||||
|
}
|
||||||
@ -31,6 +31,8 @@
|
|||||||
</header>
|
</header>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<main role="main" class="pb-3">
|
<main role="main" class="pb-3">
|
||||||
|
<partial name="_FlashMessage" />
|
||||||
|
|
||||||
@RenderBody()
|
@RenderBody()
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
11
Apps/Website/Views/Shared/_LinkItem.cshtml
Normal file
11
Apps/Website/Views/Shared/_LinkItem.cshtml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
@model Application.LinkDTO
|
||||||
|
|
||||||
|
<article>
|
||||||
|
<h2>@Model.Url</h2>
|
||||||
|
<p>
|
||||||
|
<a asp-controller="Links" asp-action="Show" asp-route-linkId="@Model.Id">Show</a>
|
||||||
|
- Published at @Model.CreatedAt.ToLongDateString()
|
||||||
|
- 🗨 @Model.CommentsCount
|
||||||
|
- 👍 @Model.UpvotesCount / 👎 @Model.DownvotesCount
|
||||||
|
</p>
|
||||||
|
</article>
|
||||||
Loading…
x
Reference in New Issue
Block a user