feat: Ajouter la fonctionnalité de suppression de commentaires avec un nouveau ViewModel

This commit is contained in:
mirage
2026-03-05 16:29:41 +01:00
parent 0c7996ae1f
commit c4206604c4
6 changed files with 123 additions and 181 deletions

View File

@@ -1,113 +0,0 @@
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
}
}