diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs
index 3088dc5..8f00a16 100644
--- a/Webzine.WebApplication/Controllers/TitreController.cs
+++ b/Webzine.WebApplication/Controllers/TitreController.cs
@@ -101,25 +101,18 @@ namespace Webzine.WebApplication.Controllers
///
/// Ajoute un like a un titre.
///
- /// Modele contenant l'identifiant du titre.
+ /// Identifiant du titre a liker.
/// Redirection vers la page detail.
[HttpPost]
- public IActionResult Like(TitreLike model)
+ public IActionResult Like(int id)
{
- this.logger.LogInformation("Ajout d'un like pour le titre ID {Id}.", model.IdTitre);
-
- var titre = this.titreRepository.Find(model.IdTitre);
-
- if (titre == null)
- {
- this.logger.LogWarning("Impossible d'ajouter un like. Titre ID {Id} introuvable.", model.IdTitre);
- }
- else
+ var titre = this.titreRepository.Find(id);
+ if (titre != null)
{
this.titreRepository.IncrementNbLikes(titre);
}
- return this.RedirectToAction("Index", new { id = model.IdTitre });
+ return this.RedirectToAction("Index", new { id });
}
///
@@ -130,29 +123,29 @@ namespace Webzine.WebApplication.Controllers
[HttpPost]
public IActionResult Comment(TitreComment model)
{
- var titre = this.titreRepository.Find(model.IdTitre);
-
- if (titre == null)
+ var titreToUpdate = this.titreRepository.Find(model.IdTitre);
+ if (titreToUpdate != null)
{
- this.logger.LogWarning("Impossible d'ajouter le commentaire. Titre ID {Id} introuvable.", model.IdTitre);
- return this.RedirectToAction("Index");
+ var commentaire = new Commentaire
+ {
+ Auteur = model.Auteur,
+ Contenu = model.Contenu,
+ DateCreation = DateTime.Now,
+ IdTitre = model.IdTitre,
+ };
+
+ titreToUpdate.Commentaires.Add(commentaire);
+ this.titreRepository.Update(titreToUpdate);
}
- var commentaire = new Commentaire
- {
- Auteur = model.Auteur,
- Contenu = model.Contenu,
- DateCreation = DateTime.Now,
- IdTitre = model.IdTitre,
- };
-
- titre.Commentaires.Add(commentaire);
-
- this.logger.LogInformation("Commentaire ajoute avec succes au titre ID {Id}.", model.IdTitre);
-
return this.RedirectToAction("Index", new { id = model.IdTitre });
}
+ ///
+ /// Mappe une entite Titre vers un item de la liste de titres pour l'affichage dans la vue de style.
+ ///
+ /// Le titre à mapper.
+ /// L'item de la liste de titres.
private static TitreStyleItem MapTitreItem(Titre titre)
{
return new TitreStyleItem
@@ -166,10 +159,10 @@ namespace Webzine.WebApplication.Controllers
}
///
- ///
+ /// Construit une URL d'intégration Spotify à partir de l'URL d'écoute d'un titre.
///
- ///
- ///
+ /// L'URL d'écoute du titre.
+ /// L'URL d'intégration Spotify ou null si l'URL n'est pas valide.
private static string? BuildSpotifyEmbedUrl(string? urlEcoute)
{
if (string.IsNullOrWhiteSpace(urlEcoute))
diff --git a/Webzine.WebApplication/Extensions/RouteConfiguration.cs b/Webzine.WebApplication/Extensions/RouteConfiguration.cs
index 0b9b428..c499adb 100644
--- a/Webzine.WebApplication/Extensions/RouteConfiguration.cs
+++ b/Webzine.WebApplication/Extensions/RouteConfiguration.cs
@@ -23,6 +23,16 @@ public static class RouteConfiguration
pattern: "artiste/{nom}",
defaults: new { controller = "Artiste", action = "Index" });
+ endpoints.MapControllerRoute(
+ name: "TitreLike",
+ pattern: "titre/{id}/like",
+ defaults: new { controller = "Titre", action = "Like" });
+
+ endpoints.MapControllerRoute(
+ name: "TitreComment",
+ pattern: "titre/{id}/comment",
+ defaults: new { controller = "Titre", action = "Comment" });
+
// ----------- ADMIN -----------
var adminRoutes = new Dictionary
{
@@ -37,7 +47,7 @@ public static class RouteConfiguration
defaults: new { area = "Administration", controller = route.Value, action = "Index" });
}
- // --- AUTRE PROUTES ---
+ // --- AUTRES ROUTES ---
endpoints.MapControllerRoute(
name: "areas",
pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
diff --git a/Webzine.WebApplication/Program.cs b/Webzine.WebApplication/Program.cs
index 4ef5711..1022096 100644
--- a/Webzine.WebApplication/Program.cs
+++ b/Webzine.WebApplication/Program.cs
@@ -150,11 +150,13 @@ try
var commentaires = new List();
var titres = SeedDataLocal.GenererListeTitre(500, artistes, styles, albums);
+ int commentaireIdStart = 1;
foreach (var titre in titres)
{
- var commentairesForTitre = SeedDataLocal.GenererListeCommentaire(titre, 0, 5);
+ var commentairesForTitre = SeedDataLocal.GenererListeCommentaire(titre, 0, 5, commentaireIdStart);
titre.Commentaires.AddRange(commentairesForTitre);
commentaires.AddRange(commentairesForTitre);
+ commentaireIdStart += commentairesForTitre.Count;
}
store.Artistes.AddRange(artistes);
diff --git a/Webzine.WebApplication/Views/Titre/Index.cshtml b/Webzine.WebApplication/Views/Titre/Index.cshtml
index 6b410bf..c5a1c6f 100644
--- a/Webzine.WebApplication/Views/Titre/Index.cshtml
+++ b/Webzine.WebApplication/Views/Titre/Index.cshtml
@@ -59,12 +59,11 @@