From 909ed0e67b7ef12ee09227019aad1bf48e63099a Mon Sep 17 00:00:00 2001 From: Florlan Date: Thu, 5 Mar 2026 13:07:50 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Feat:=20Commentaire=20-=20cr=C3=A9ation=20d?= =?UTF-8?q?e=20la=20route=20commentaire=20dans=20program.cs=20-=20cr=C3=A9?= =?UTF-8?q?ation=20du=20CommentairesController=20-=20cr=C3=A9ation=20du=20?= =?UTF-8?q?CommentaireViewModel=20-=20cr=C3=A9ation=20de=20la=20vue=20inde?= =?UTF-8?q?x.cshtml=20des=20commentaire=20-=20cr=C3=A9ation=20du=20layout?= =?UTF-8?q?=20Admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Views/Commentaires/Index.cshtml | 90 +++++++++ .../Areas/Admin/Views/Shared/_Layout.cshtml | 181 ++++++++++++++++++ .../Controllers/CommentairesController.cs | 113 +++++++++++ Webzine.WebApplication/Program.cs | 6 + .../ViewModels/CommentaireViewModel.cs | 19 ++ .../Webzine.WebApplication.csproj | 9 +- 6 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml create mode 100644 Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml create mode 100644 Webzine.WebApplication/Controllers/CommentairesController.cs create mode 100644 Webzine.WebApplication/ViewModels/CommentaireViewModel.cs diff --git a/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml b/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml new file mode 100644 index 0000000..0199999 --- /dev/null +++ b/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml @@ -0,0 +1,90 @@ +@using Webzine.WebApplication.ViewModels +@using Webzine.Entity +@model CommentaireViewModel + +@{ + ViewData["Title"] = "Commentaires"; + Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml"; +} + + + +

Commentaires

+ +
+ + + + + + + + + + + + @foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires) + { + + + + + + + + } + +
TitreAuteurCommentaireDate de créationActions
+ + @(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu") + + + @commentaire.Auteur + + @commentaire.Contenu + + @commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") + + +
+ @Html.AntiForgeryToken() + +
+
+
diff --git a/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..559941b --- /dev/null +++ b/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml @@ -0,0 +1,181 @@ + + + + + + @ViewData["Title"] - Administration + + + + + + +
+
+ @RenderBody() +
+
+ + \ No newline at end of file diff --git a/Webzine.WebApplication/Controllers/CommentairesController.cs b/Webzine.WebApplication/Controllers/CommentairesController.cs new file mode 100644 index 0000000..9c60b25 --- /dev/null +++ b/Webzine.WebApplication/Controllers/CommentairesController.cs @@ -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 + { + 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 + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 575f1cf..c9ca7ea 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -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). // Equivalent � app.MapDefaultControllerRoute() diff --git a/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs b/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs new file mode 100644 index 0000000..cbd09da --- /dev/null +++ b/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Webzine. All rights reserved. +// + +using Webzine.Entity; + +namespace Webzine.WebApplication.ViewModels +{ + /// + /// ViewModel pour afficher la liste des commentaires en administration. + /// + public class CommentaireViewModel + { + /// + /// Obtient ou définit la liste des commentaires. + /// + public IEnumerable Commentaires { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Webzine.WebApplication.csproj b/Webzine.WebApplication/Webzine.WebApplication.csproj index 5651896..4f72671 100644 --- a/Webzine.WebApplication/Webzine.WebApplication.csproj +++ b/Webzine.WebApplication/Webzine.WebApplication.csproj @@ -17,6 +17,7 @@ + @@ -25,12 +26,16 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + From aa5bffee27e6200debce0c496fa131395221ac0e Mon Sep 17 00:00:00 2001 From: "b.nodon" Date: Thu, 5 Mar 2026 13:22:36 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Feat:=20Commentaire=20-=20cr=C3=A9ation=20d?= =?UTF-8?q?e=20la=20route=20commentaire=20dans=20program.cs=20-=20cr=C3=A9?= =?UTF-8?q?ation=20du=20CommentairesController=20-=20cr=C3=A9ation=20du=20?= =?UTF-8?q?CommentaireViewModel=20-=20cr=C3=A9ation=20de=20la=20vue=20inde?= =?UTF-8?q?x.cshtml=20des=20commentaire=20-=20cr=C3=A9ation=20du=20layout?= =?UTF-8?q?=20Admin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Views/Commentaires/Index.cshtml | 90 +++++++++ .../Areas/Admin/Views/Shared/_Layout.cshtml | 181 ++++++++++++++++++ .../Controllers/CommentairesController.cs | 113 +++++++++++ Webzine.WebApplication/Program.cs | 6 + .../ViewModels/CommentaireViewModel.cs | 19 ++ .../Webzine.WebApplication.csproj | 9 +- 6 files changed, 416 insertions(+), 2 deletions(-) create mode 100644 Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml create mode 100644 Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml create mode 100644 Webzine.WebApplication/Controllers/CommentairesController.cs create mode 100644 Webzine.WebApplication/ViewModels/CommentaireViewModel.cs diff --git a/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml b/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml new file mode 100644 index 0000000..0199999 --- /dev/null +++ b/Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml @@ -0,0 +1,90 @@ +@using Webzine.WebApplication.ViewModels +@using Webzine.Entity +@model CommentaireViewModel + +@{ + ViewData["Title"] = "Commentaires"; + Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml"; +} + + + +

Commentaires

+ +
+ + + + + + + + + + + + @foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires) + { + + + + + + + + } + +
TitreAuteurCommentaireDate de créationActions
+ + @(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu") + + + @commentaire.Auteur + + @commentaire.Contenu + + @commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") + + +
+ @Html.AntiForgeryToken() + +
+
+
diff --git a/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..559941b --- /dev/null +++ b/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml @@ -0,0 +1,181 @@ + + + + + + @ViewData["Title"] - Administration + + + + + + +
+
+ @RenderBody() +
+
+ + \ No newline at end of file diff --git a/Webzine.WebApplication/Controllers/CommentairesController.cs b/Webzine.WebApplication/Controllers/CommentairesController.cs new file mode 100644 index 0000000..9c60b25 --- /dev/null +++ b/Webzine.WebApplication/Controllers/CommentairesController.cs @@ -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 + { + 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 + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 575f1cf..c9ca7ea 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -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). // Equivalent � app.MapDefaultControllerRoute() diff --git a/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs b/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs new file mode 100644 index 0000000..cbd09da --- /dev/null +++ b/Webzine.WebApplication/ViewModels/CommentaireViewModel.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Webzine. All rights reserved. +// + +using Webzine.Entity; + +namespace Webzine.WebApplication.ViewModels +{ + /// + /// ViewModel pour afficher la liste des commentaires en administration. + /// + public class CommentaireViewModel + { + /// + /// Obtient ou définit la liste des commentaires. + /// + public IEnumerable Commentaires { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Webzine.WebApplication.csproj b/Webzine.WebApplication/Webzine.WebApplication.csproj index 5651896..4f72671 100644 --- a/Webzine.WebApplication/Webzine.WebApplication.csproj +++ b/Webzine.WebApplication/Webzine.WebApplication.csproj @@ -17,6 +17,7 @@
+ @@ -25,12 +26,16 @@ - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + From 0c7996ae1f04ff9d21cec19729e1efa201f20b9c Mon Sep 17 00:00:00 2001 From: "b.nodon" Date: Thu, 5 Mar 2026 15:28:27 +0100 Subject: [PATCH 3/4] =?UTF-8?q?Rework=20#30=20#31=20#43=20:=20-=20Changeme?= =?UTF-8?q?nt=20de=20la=20route=20-=20CSS=20remplac=C3=A9=20par=20bootstra?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Webzine.Entity/Style.cs | 2 + Webzine.Entity/Titre.cs | 2 + Webzine.Repository/LocalEntityRepository.cs | 30 +-- .../Admin/Views/Commentaires/Index.cshtml | 90 --------- .../Areas/Admin/Views/Shared/_Layout.cshtml | 181 ------------------ .../Controllers/CommentairesController.cs | 113 +++++++++++ .../ViewModels/CommentaireViewModel.cs | 24 +++ .../Views/Commentaires/Index.cshtml | 52 +++++ .../Views/Shared/_Header.cshtml | 58 ++++++ .../Views/Shared/_Layout.cshtml | 19 ++ .../Administration/Views/_ViewImports.cshtml | 2 + .../Administration/Views/_ViewStart.cshtml | 3 + Webzine.WebApplication/Program.cs | 9 +- .../Webzine.WebApplication.csproj | 6 +- 14 files changed, 284 insertions(+), 307 deletions(-) delete mode 100644 Webzine.WebApplication/Areas/Admin/Views/Commentaires/Index.cshtml delete mode 100644 Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml create mode 100644 Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs create mode 100644 Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs create mode 100644 Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml create mode 100644 Webzine.WebApplication/Areas/Administration/Views/Shared/_Header.cshtml create mode 100644 Webzine.WebApplication/Areas/Administration/Views/Shared/_Layout.cshtml create mode 100644 Webzine.WebApplication/Areas/Administration/Views/_ViewImports.cshtml create mode 100644 Webzine.WebApplication/Areas/Administration/Views/_ViewStart.cshtml diff --git a/Webzine.Entity/Style.cs b/Webzine.Entity/Style.cs index 11c6f32..655e272 100644 --- a/Webzine.Entity/Style.cs +++ b/Webzine.Entity/Style.cs @@ -18,5 +18,7 @@ namespace Webzine.Entity [Display(Name = "Libellé")] public string Libelle { get; set; } + + public List Titres { get; set; } = new List(); } } diff --git a/Webzine.Entity/Titre.cs b/Webzine.Entity/Titre.cs index 2fd9671..41aa07f 100644 --- a/Webzine.Entity/Titre.cs +++ b/Webzine.Entity/Titre.cs @@ -63,5 +63,7 @@ namespace Webzine.Entity public List Commentaires { get; set; } + + public List - -

Commentaires

- -
- - - - - - - - - - - - @foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires) - { - - - - - - - - } - -
TitreAuteurCommentaireDate de créationActions
- - @(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu") - - - @commentaire.Auteur - - @commentaire.Contenu - - @commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") - - -
- @Html.AntiForgeryToken() - -
-
-
diff --git a/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml deleted file mode 100644 index 559941b..0000000 --- a/Webzine.WebApplication/Areas/Admin/Views/Shared/_Layout.cshtml +++ /dev/null @@ -1,181 +0,0 @@ - - - - - - @ViewData["Title"] - Administration - - - - - - -
-
- @RenderBody() -
-
- - \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs new file mode 100644 index 0000000..8f47c7f --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Webzine.Entity; +using Webzine.WebApplication.Areas.Administration.ViewModels; + +namespace Webzine.WebApplication.Areas.Administration.Controllers +{ + [Area("Administration")] + public class CommentairesController : Controller + { + // GET: Administration/Commentaires + public ActionResult Index() + { + // Création de données "bouchon" (mock) pour tester l'affichage + var listeCommentaires = new List + { + 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 + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs b/Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs new file mode 100644 index 0000000..f2d8c5c --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs @@ -0,0 +1,24 @@ +// +// Copyright (c) Webzine. All rights reserved. +// + + +// +// Copyright (c) Webzine. All rights reserved. +// + +using Webzine.Entity; + +namespace Webzine.WebApplication.Areas.Administration.ViewModels +{ + /// + /// ViewModel pour afficher la liste des commentaires en administration. + /// + public class CommentaireViewModel + { + /// + /// Obtient ou définit la liste des commentaires. + /// + public IEnumerable Commentaires { get; set; } = new List(); + } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml b/Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml new file mode 100644 index 0000000..fbb1915 --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml @@ -0,0 +1,52 @@ +@model Webzine.WebApplication.Areas.Administration.ViewModels.CommentaireViewModel + +@{ + ViewData["Title"] = "Commentaires"; +} + + +
+

Commentaires

+ +
+ + + + + + + + + + + + @foreach (Webzine.Entity.Commentaire commentaire in Model.Commentaires) + { + + + + + + + + } + +
TitreAuteurCommentaireDate de créationActions
+ @(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu") + + @commentaire.Auteur + + @commentaire.Contenu + + @commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") + +
+ @Html.AntiForgeryToken() + + +
+
+
+
\ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/Shared/_Header.cshtml b/Webzine.WebApplication/Areas/Administration/Views/Shared/_Header.cshtml new file mode 100644 index 0000000..9a66f6e --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/Shared/_Header.cshtml @@ -0,0 +1,58 @@ +@* + For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 +*@ +@{ +} +
+ +
\ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/Shared/_Layout.cshtml b/Webzine.WebApplication/Areas/Administration/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000..a3cfc53 --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/Shared/_Layout.cshtml @@ -0,0 +1,19 @@ + + + + + + @ViewData["Title"] - Webzine + + @* Ajout de bootstrap *@ + + + + @* Ajout de font-awesome *@ + + + + @await Html.PartialAsync("_Header") + @RenderBody() + + \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/_ViewImports.cshtml b/Webzine.WebApplication/Areas/Administration/Views/_ViewImports.cshtml new file mode 100644 index 0000000..505b08b --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/_ViewImports.cshtml @@ -0,0 +1,2 @@ +@* Permet de factoriser les imports de tag helpers *@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/_ViewStart.cshtml b/Webzine.WebApplication/Areas/Administration/Views/_ViewStart.cshtml new file mode 100644 index 0000000..d641c67 --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} \ No newline at end of file diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs index 52780d6..e52b728 100644 --- a/Webzine.WebApplication/Program.cs +++ b/Webzine.WebApplication/Program.cs @@ -24,7 +24,7 @@ try builder.Host.UseNLog(); // Register LocalEntityRepository as a singleton - builder.Services.AddSingleton(); + //builder.Services.AddSingleton(); var app = builder.Build(); @@ -49,12 +49,7 @@ try // Permet de remplir les listes d'entités du repository avec des donn�es de test. - using (var scope = app.Services.CreateScope()) - { - var repository = scope.ServiceProvider.GetRequiredService(); - repository.Seed(); - } - + app.Run(); } catch (Exception exception) diff --git a/Webzine.WebApplication/Webzine.WebApplication.csproj b/Webzine.WebApplication/Webzine.WebApplication.csproj index e63f5dd..66802fe 100644 --- a/Webzine.WebApplication/Webzine.WebApplication.csproj +++ b/Webzine.WebApplication/Webzine.WebApplication.csproj @@ -24,7 +24,6 @@
- @@ -40,4 +39,9 @@ + + + + + From c4206604c4bcb8df1963a620fe789dc56f6246fb Mon Sep 17 00:00:00 2001 From: mirage <119869686+ClementBobin@users.noreply.github.com> Date: Thu, 5 Mar 2026 16:29:41 +0100 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20Ajouter=20la=20fonctionnalit=C3=A9?= =?UTF-8?q?=20de=20suppression=20de=20commentaires=20avec=20un=20nouveau?= =?UTF-8?q?=20ViewModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommentairesController.cs | 114 +++++++++--------- .../Commentaire/CommentaireDeleteViewModel.cs | 14 +++ .../{ => Commentaire}/CommentaireViewModel.cs | 7 +- .../Views/Commentaire/Delete.cshtml | 42 +++++++ .../Index.cshtml | 14 +-- .../Controllers/CommentairesController.cs | 113 ----------------- 6 files changed, 123 insertions(+), 181 deletions(-) create mode 100644 Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireDeleteViewModel.cs rename Webzine.WebApplication/Areas/Administration/ViewModels/{ => Commentaire}/CommentaireViewModel.cs (83%) create mode 100644 Webzine.WebApplication/Areas/Administration/Views/Commentaire/Delete.cshtml rename Webzine.WebApplication/Areas/Administration/Views/{Commentaires => Commentaire}/Index.cshtml (66%) delete mode 100644 Webzine.WebApplication/Controllers/CommentairesController.cs diff --git a/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs b/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs index 8f47c7f..820cb0f 100644 --- a/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs +++ b/Webzine.WebApplication/Areas/Administration/Controllers/CommentairesController.cs @@ -3,13 +3,38 @@ using System.Collections.Generic; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Webzine.Entity; -using Webzine.WebApplication.Areas.Administration.ViewModels; +using Webzine.Entity.Fixtures; +using Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire; namespace Webzine.WebApplication.Areas.Administration.Controllers { [Area("Administration")] - public class CommentairesController : Controller + public class CommentaireController : Controller { + private readonly ILogger _logger; + private readonly List _commentaires; + /// + /// Initialise une nouvelle instance du . + /// Les données sont générées dynamiquement via . + /// + /// Service de journalisation injecté. + public CommentaireController(ILogger 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() { @@ -53,61 +78,42 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers } - - // 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 + // GET: Administration/Commentaires/Delete/5 public ActionResult Delete(int id) { - return View(); + 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: CommentairesController/Delete/5 + // 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); + } + } } } \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireDeleteViewModel.cs b/Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireDeleteViewModel.cs new file mode 100644 index 0000000..9b6b8c6 --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireDeleteViewModel.cs @@ -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; } +} \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs b/Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireViewModel.cs similarity index 83% rename from Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs rename to Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireViewModel.cs index f2d8c5c..3ce7115 100644 --- a/Webzine.WebApplication/Areas/Administration/ViewModels/CommentaireViewModel.cs +++ b/Webzine.WebApplication/Areas/Administration/ViewModels/Commentaire/CommentaireViewModel.cs @@ -6,10 +6,7 @@ // // Copyright (c) Webzine. All rights reserved. // - -using Webzine.Entity; - -namespace Webzine.WebApplication.Areas.Administration.ViewModels +namespace Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire { /// /// ViewModel pour afficher la liste des commentaires en administration. @@ -19,6 +16,6 @@ namespace Webzine.WebApplication.Areas.Administration.ViewModels /// /// Obtient ou définit la liste des commentaires. /// - public IEnumerable Commentaires { get; set; } = new List(); + public IEnumerable Commentaires { get; set; } = new List(); } } \ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/Commentaire/Delete.cshtml b/Webzine.WebApplication/Areas/Administration/Views/Commentaire/Delete.cshtml new file mode 100644 index 0000000..f9fa126 --- /dev/null +++ b/Webzine.WebApplication/Areas/Administration/Views/Commentaire/Delete.cshtml @@ -0,0 +1,42 @@ +@model Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire.CommentaireDeleteViewModel + +@{ + ViewData["Title"] = "Supprimer un commentaire"; +} + +
+ +

Supprimer un commentaire

+
+ +

+ Êtes-vous sûr de vouloir supprimer le commentaire suivant ? +

+ +
+

@Model.Contenu

+ +
+ — @Model.Auteur + le @Model.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") + sur @Model.TitreLibelle +
+
+ +
+ + + +
+ +
+
+ + + Retour à l'administration des commentaires + + +
\ No newline at end of file diff --git a/Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml b/Webzine.WebApplication/Areas/Administration/Views/Commentaire/Index.cshtml similarity index 66% rename from Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml rename to Webzine.WebApplication/Areas/Administration/Views/Commentaire/Index.cshtml index fbb1915..c8241d3 100644 --- a/Webzine.WebApplication/Areas/Administration/Views/Commentaires/Index.cshtml +++ b/Webzine.WebApplication/Areas/Administration/Views/Commentaire/Index.cshtml @@ -1,4 +1,4 @@ -@model Webzine.WebApplication.Areas.Administration.ViewModels.CommentaireViewModel +@model Webzine.WebApplication.Areas.Administration.ViewModels.Commentaire.CommentaireViewModel @{ ViewData["Title"] = "Commentaires"; @@ -24,7 +24,7 @@ { - @(commentaire.Titre != null ? commentaire.Titre.Libelle : "Titre inconnu") + @commentaire.Titre.Libelle @commentaire.Auteur @@ -36,13 +36,9 @@ @commentaire.DateCreation.ToString("dd/MM/yyyy HH:mm:ss") -
- @Html.AntiForgeryToken() - - -
+ + + } diff --git a/Webzine.WebApplication/Controllers/CommentairesController.cs b/Webzine.WebApplication/Controllers/CommentairesController.cs deleted file mode 100644 index 9c60b25..0000000 --- a/Webzine.WebApplication/Controllers/CommentairesController.cs +++ /dev/null @@ -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 - { - 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 - } -} \ No newline at end of file