Merge pull request 'j1/feat/admin_page_commentaire' (#58) from j1/feat/admin_page_commentaire into dev
Reviewed-on: http://10.4.0.131/DI1-P4-E1/Webzine/pulls/58
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Webzine.Entity;
|
||||
using Webzine.Entity.Fixtures;
|
||||
using Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire;
|
||||
|
||||
namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
[Area("Administration")]
|
||||
public class CommentaireController : Controller
|
||||
{
|
||||
private readonly ILogger<CommentaireController> _logger;
|
||||
private readonly List<Commentaire> _commentaires;
|
||||
/// <summary>
|
||||
/// Initialise une nouvelle instance du <see cref="CommentaireController"/>.
|
||||
/// Les données sont générées dynamiquement via <see cref="DataFactory"/>.
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
public CommentaireController(ILogger<CommentaireController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
||||
_logger.LogInformation("Initialisation du contrôleur CommentaireController.");
|
||||
|
||||
var factory = new DataFactory();
|
||||
|
||||
var _artistes = factory.GenerateArtists(10);
|
||||
var _styles = factory.GenerateStyles(10);
|
||||
var _titres = factory.GenerateTitres(30, _artistes, _styles);
|
||||
|
||||
_commentaires = factory.GenerateCommentaires(50, _titres);
|
||||
|
||||
_logger.LogInformation("Données fictives générées avec succès.");
|
||||
}
|
||||
|
||||
// GET: Administration/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: Administration/Commentaires/Delete/5
|
||||
public ActionResult Delete(int id)
|
||||
{
|
||||
var commentaire = _commentaires
|
||||
.FirstOrDefault(c => c.IdCommentaire == id);
|
||||
|
||||
if (commentaire == null)
|
||||
return NotFound();
|
||||
|
||||
var vm = new CommentaireDeleteViewModel
|
||||
{
|
||||
IdCommentaire = commentaire.IdCommentaire,
|
||||
Auteur = commentaire.Auteur,
|
||||
Contenu = commentaire.Contenu,
|
||||
DateCreation = commentaire.DateCreation,
|
||||
TitreLibelle = commentaire.Titre?.Libelle
|
||||
};
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
// POST: Administration/Commentaires/Delete/5
|
||||
[HttpPost]
|
||||
[ValidateAntiForgeryToken]
|
||||
public ActionResult Delete(int id, CommentaireDeleteViewModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
return RedirectToAction();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Log de l'erreur
|
||||
Console.WriteLine(e);
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire;
|
||||
|
||||
public class CommentaireDeleteViewModel
|
||||
{
|
||||
public int IdCommentaire { get; set; }
|
||||
|
||||
public string? Auteur { get; set; }
|
||||
|
||||
public string? Contenu { get; set; }
|
||||
|
||||
public DateTime DateCreation { get; set; }
|
||||
|
||||
public string? TitreLibelle { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// <copyright file="CommentaireViewModel.cs" company="Webzine">
|
||||
// Copyright (c) Webzine. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
|
||||
// <copyright file="CommentaireViewModel.cs" company="Webzine">
|
||||
// Copyright (c) Webzine. All rights reserved.
|
||||
// </copyright>
|
||||
namespace Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire
|
||||
{
|
||||
/// <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<Entity.Commentaire> Commentaires { get; set; } = new List<Entity.Commentaire>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire.CommentaireDeleteViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Supprimer un commentaire";
|
||||
}
|
||||
|
||||
<div class="container mt-4">
|
||||
|
||||
<h1 class="mb-3">Supprimer un commentaire</h1>
|
||||
<hr />
|
||||
|
||||
<p class="mb-4">
|
||||
Êtes-vous sûr de vouloir supprimer le commentaire suivant ?
|
||||
</p>
|
||||
|
||||
<div class="mb-4">
|
||||
<h4>@Model.Contenu</h4>
|
||||
|
||||
<div class="text-muted">
|
||||
— <strong>@Model.Auteur</strong>
|
||||
le @Model.DateCreation.ToString("dd/MM/yyyy HH:mm:ss")
|
||||
sur <em>@Model.TitreLibelle</em>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form asp-action="Delete" method="post">
|
||||
<input type="hidden" asp-for="IdCommentaire" />
|
||||
|
||||
<button type="submit" class="btn btn-danger">
|
||||
Supprimer
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<a asp-action="Index"
|
||||
class="btn-link">
|
||||
Retour à l'administration des commentaires
|
||||
</a>
|
||||
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
@model Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire.CommentaireViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Commentaires";
|
||||
}
|
||||
|
||||
|
||||
<div class="justify-content-center m-5">
|
||||
<h1 class="mb-4">Commentaires</h1>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover table-bordered">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th scope="col">Titre</th>
|
||||
<th scope="col">Auteur</th>
|
||||
<th scope="col">Commentaire</th>
|
||||
<th scope="col">Date de création</th>
|
||||
<th scope="col" class="text-center">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires)
|
||||
{
|
||||
<tr class="align-middle">
|
||||
<td>
|
||||
@commentaire.Titre.Libelle
|
||||
</td>
|
||||
<td>
|
||||
@commentaire.Auteur
|
||||
</td>
|
||||
<td>
|
||||
@commentaire.Contenu
|
||||
</td>
|
||||
<td>
|
||||
@commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss")
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a asp-action="Delete" asp-route-id="@commentaire.IdCommentaire" class="d-inline btn btn-link text-primary">
|
||||
<i class="fas fa-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,58 @@
|
||||
@*
|
||||
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
*@
|
||||
@{
|
||||
}
|
||||
<header>
|
||||
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
|
||||
<div class="container-fluid">
|
||||
|
||||
<!-- Logo -->
|
||||
<a class="navbar-brand" href="#">Webzine</a>
|
||||
|
||||
<!-- bouton mobile -->
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarWebzine">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarWebzine">
|
||||
|
||||
<!-- Menu -->
|
||||
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" href="#">
|
||||
<i class="fa-solid fa-house"></i> Accueil
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@* TODO : Modifier, il s'agit d'une liste *@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">
|
||||
<i class="fa-solid fa-screwdriver-wrench"></i> Administration
|
||||
</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="#">
|
||||
<i class="fa-solid fa-envelope"></i> Contact
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<!-- Barre de recherche -->
|
||||
<form class="d-flex">
|
||||
<div class="input-group">
|
||||
<div class="form-outline">
|
||||
<input class="form-control me-2" type="search" placeholder="Trouver un artiste / titre">
|
||||
</div>
|
||||
<button class="btn btn-primary" type="submit">
|
||||
<i class="fa-solid fa-magnifying-glass"></i>
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
@@ -0,0 +1,19 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>@ViewData["Title"] - Webzine</title>
|
||||
|
||||
@* Ajout de bootstrap *@
|
||||
<script src="/js/bootstrap.min.js" defer></script>
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
|
||||
@* Ajout de font-awesome *@
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
|
||||
</head>
|
||||
<body>
|
||||
@await Html.PartialAsync("_Header")
|
||||
@RenderBody()
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,2 @@
|
||||
@* Permet de factoriser les imports de tag helpers *@
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@@ -0,0 +1,3 @@
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
}
|
||||
@@ -30,6 +30,12 @@ try
|
||||
// Active le middleware permettant le routage des requétes entrantes.
|
||||
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
|
||||
// avec la forme /controller/action/id(optionnel).
|
||||
app.MapControllerRoute(
|
||||
|
||||
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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user