Feat: Commentaire
- création de la route commentaire dans program.cs - création du CommentairesController - création du CommentaireViewModel - création de la vue index.cshtml des commentaire - création du layout Admin
This commit is contained in:
@@ -0,0 +1,90 @@
|
|||||||
|
@using Webzine.WebApplication.ViewModels
|
||||||
|
@using Webzine.Entity
|
||||||
|
@model CommentaireViewModel
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Commentaires";
|
||||||
|
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
|
||||||
|
}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.commentaires-container {
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commentaires-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse;
|
||||||
|
margin-top: 1.5rem;
|
||||||
|
background: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commentaires-table thead {
|
||||||
|
background: #ddd;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.commentaires-table th, .commentaires-table td {
|
||||||
|
padding: 1rem;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-delete {
|
||||||
|
color: #0066cc;
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-delete:hover {
|
||||||
|
color: #ff4444;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<h1>Commentaires</h1>
|
||||||
|
|
||||||
|
<div class="commentaires-container">
|
||||||
|
<table class="commentaires-table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Titre</th>
|
||||||
|
<th>Auteur</th>
|
||||||
|
<th>Commentaire</th>
|
||||||
|
<th>Date de création</th>
|
||||||
|
<th style="text-align: center;">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<!-- Titre est un objet, on affiche sa propriété Libelle -->
|
||||||
|
@(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu")
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<!-- On utilise Auteur (et pas Nom) -->
|
||||||
|
@commentaire.Auteur
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@commentaire.Contenu
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss")
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center;">
|
||||||
|
<!-- On utilise IdCommentaire (et pas Id) -->
|
||||||
|
<form method="post" action="@Url.Action("Delete", new { id = commentaire.IdCommentaire })" style="display: inline;">
|
||||||
|
@Html.AntiForgeryToken()
|
||||||
|
<button type="submit" class="btn-delete" title="Supprimer">
|
||||||
|
<i class="fas fa-trash"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
181
Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml
Normal file
181
Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml
Normal file
@@ -0,0 +1,181 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="fr">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>@ViewData["Title"] - Administration</title>
|
||||||
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
|
||||||
|
<style>
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
body { font-family: Arial, sans-serif; background: #f5f5f5; }
|
||||||
|
|
||||||
|
.navbar {
|
||||||
|
background: #2b2b2b;
|
||||||
|
color: white;
|
||||||
|
padding: 0.75rem 2rem;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-left {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-logo {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
font-weight: bold;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-menu {
|
||||||
|
display: flex;
|
||||||
|
gap: 1.5rem;
|
||||||
|
list-style: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-menu a {
|
||||||
|
color: #999;
|
||||||
|
text-decoration: none;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.5rem;
|
||||||
|
transition: color 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-menu a:hover {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-menu a i {
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu {
|
||||||
|
display: none;
|
||||||
|
position: absolute;
|
||||||
|
top: 100%;
|
||||||
|
left: 0;
|
||||||
|
background: #1a1a1a;
|
||||||
|
min-width: 200px;
|
||||||
|
padding: 0.5rem 0;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 0 4px 8px rgba(0,0,0,0.3);
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
z-index: 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu a {
|
||||||
|
display: block;
|
||||||
|
padding: 0.75rem 1.5rem;
|
||||||
|
color: #999;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown-menu a:hover {
|
||||||
|
background: #2b2b2b;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dropdown:hover .dropdown-menu {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.5rem;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search input {
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
width: 250px;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search button {
|
||||||
|
background: #0066cc;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 0.5rem 1rem;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background 0.3s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search button:hover {
|
||||||
|
background: #0052a3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
padding: 2rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-content {
|
||||||
|
background: white;
|
||||||
|
padding: 2rem;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
media (max-width: 768px) {
|
||||||
|
.navbar {
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-menu {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search {
|
||||||
|
width: 100%;
|
||||||
|
margin-top: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.navbar-search input {
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<nav class="navbar">
|
||||||
|
<div class="navbar-left">
|
||||||
|
<a href="/" class="navbar-logo">Webzine</a>
|
||||||
|
<ul class="navbar-menu">
|
||||||
|
<li><a href="/"><i class="fas fa-home"></i> Accueil</a></li>
|
||||||
|
<li class="dropdown">
|
||||||
|
<a href="#"><i class="fas fa-key"></i> Administration</a>
|
||||||
|
<div class="dropdown-menu">
|
||||||
|
<a href="/Admin/Commentaires"><i class="fas fa-comments"></i> Commentaires</a>
|
||||||
|
<a href="/Admin"><i class="fas fa-file-alt"></i> Articles</a>
|
||||||
|
<a href="/Admin"><i class="fas fa-users"></i> Utilisateurs</a>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li><a href="/contact"><i class="fas fa-envelope"></i> Contact</a></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form class="navbar-search" method="get" action="/search">
|
||||||
|
<input type="text" name="q" placeholder="Trouver un artiste / titre" />
|
||||||
|
<button type="submit"><i class="fas fa-search"></i></button>
|
||||||
|
</form>
|
||||||
|
</nav>
|
||||||
|
|
||||||
|
<div class="container">
|
||||||
|
<main class="main-content">
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
113
Webzine.WebApplication/Controllers/CommentairesController.cs
Normal file
113
Webzine.WebApplication/Controllers/CommentairesController.cs
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Webzine.Entity;
|
||||||
|
using Webzine.WebApplication.ViewModels;
|
||||||
|
|
||||||
|
namespace Webzine.WebApplication.Controllers
|
||||||
|
{
|
||||||
|
[Area("Admin")]
|
||||||
|
public class CommentairesController : Controller
|
||||||
|
{
|
||||||
|
// GET: Admin/Commentaires
|
||||||
|
public ActionResult Index()
|
||||||
|
{
|
||||||
|
// Création de données "bouchon" (mock) pour tester l'affichage
|
||||||
|
var listeCommentaires = new List<Commentaire>
|
||||||
|
{
|
||||||
|
new Commentaire
|
||||||
|
{
|
||||||
|
IdCommentaire = 1, // Correction: Id -> IdCommentaire
|
||||||
|
Auteur = "Michel", // Correction: Nom -> Auteur
|
||||||
|
Contenu = "Nulla sed velit nec tellus gravida molestie",
|
||||||
|
DateCreation = new DateTime(2023, 1, 22, 15, 59, 28),
|
||||||
|
// Important : On initialise l'objet Titre pour accéder à Titre.Libelle
|
||||||
|
Titre = new Titre { Libelle = "St Germain - So Flute" },
|
||||||
|
},
|
||||||
|
new Commentaire
|
||||||
|
{
|
||||||
|
IdCommentaire = 2,
|
||||||
|
Auteur = "Jeff",
|
||||||
|
Contenu = "Lorem ipsum dolor sit.",
|
||||||
|
DateCreation = new DateTime(2023, 1, 22, 14, 27, 8),
|
||||||
|
Titre = new Titre { Libelle = "Queen - Bohemian Rapsody" },
|
||||||
|
},
|
||||||
|
new Commentaire
|
||||||
|
{
|
||||||
|
IdCommentaire = 3,
|
||||||
|
Auteur = "Eva",
|
||||||
|
Contenu = "Aenean vulputate eleifend tellus.",
|
||||||
|
DateCreation = new DateTime(2023, 1, 22, 13, 2, 17),
|
||||||
|
Titre = new Titre { Libelle = "Rammstein - Du hast" },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initialisation du ViewModel
|
||||||
|
var viewModel = new CommentaireViewModel
|
||||||
|
{
|
||||||
|
Commentaires = listeCommentaires
|
||||||
|
};
|
||||||
|
|
||||||
|
return View(viewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// GET: CommentairesController/Details/5
|
||||||
|
public ActionResult Details(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: CommentairesController/Create
|
||||||
|
public ActionResult Create()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: CommentairesController/Create
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult Create(IFormCollection collection)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: CommentairesController/Edit/5
|
||||||
|
public ActionResult Edit(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: CommentairesController/Edit/5
|
||||||
|
[HttpPost]
|
||||||
|
[ValidateAntiForgeryToken]
|
||||||
|
public ActionResult Edit(int id, IFormCollection collection)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return RedirectToAction(nameof(Index));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: CommentairesController/Delete/5
|
||||||
|
public ActionResult Delete(int id)
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: CommentairesController/Delete/5
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,12 @@ try
|
|||||||
// Active le middleware permettant le routage des requ<71>tes entrantes.
|
// Active le middleware permettant le routage des requ<71>tes entrantes.
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
|
|
||||||
|
// Ajoute une route pour les zones (Areas) comme Admin
|
||||||
|
app.MapControllerRoute(
|
||||||
|
name: "areas",
|
||||||
|
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
// Ajoute un endpoint permettant de router les urls
|
// Ajoute un endpoint permettant de router les urls
|
||||||
// avec la forme /controller/action/id(optionnel).
|
// avec la forme /controller/action/id(optionnel).
|
||||||
// Equivalent <20> app.MapDefaultControllerRoute()
|
// Equivalent <20> app.MapDefaultControllerRoute()
|
||||||
|
|||||||
19
Webzine.WebApplication/ViewModels/CommentaireViewModel.cs
Normal file
19
Webzine.WebApplication/ViewModels/CommentaireViewModel.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
// <copyright file="CommentaireViewModel.cs" company="Webzine">
|
||||||
|
// Copyright (c) Webzine. All rights reserved.
|
||||||
|
// </copyright>
|
||||||
|
|
||||||
|
using Webzine.Entity;
|
||||||
|
|
||||||
|
namespace Webzine.WebApplication.ViewModels
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ViewModel pour afficher la liste des commentaires en administration.
|
||||||
|
/// </summary>
|
||||||
|
public class CommentaireViewModel
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Obtient ou définit la liste des commentaires.
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<Commentaire> Commentaires { get; set; } = new List<Commentaire>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="Areas\Admin\Controllers\" />
|
||||||
<Folder Include="wwwroot\data\" />
|
<Folder Include="wwwroot\data\" />
|
||||||
<Folder Include="wwwroot\js\" />
|
<Folder Include="wwwroot\js\" />
|
||||||
<Folder Include="wwwroot\lib\" />
|
<Folder Include="wwwroot\lib\" />
|
||||||
@@ -25,12 +26,16 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Faker.Net" Version="2.0.163" />
|
<PackageReference Include="Faker.Net" Version="2.0.163" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.3" />
|
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="10.0.3" />
|
||||||
<PackageReference Include="NLog.Web.AspNetCore" Version="5.*" />
|
<PackageReference Include="NLog.Web.AspNetCore" Version="6.1.1" />
|
||||||
<PackageReference Include="NLog" Version="5.*" />
|
<PackageReference Include="NLog" Version="6.1.1" />
|
||||||
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Webzine.Entity\Webzine.Entity.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user