diff --git a/Webzine.Repository.Contracts/ITitreRepository.cs b/Webzine.Repository.Contracts/ITitreRepository.cs
index 4f19c38..394b601 100644
--- a/Webzine.Repository.Contracts/ITitreRepository.cs
+++ b/Webzine.Repository.Contracts/ITitreRepository.cs
@@ -72,6 +72,22 @@
/// Une collection de titres correspondant au critère de recherche, triée par libellé.
IEnumerable SearchByStyle(string libelle);
+ ///
+ /// Retourne une liste de titre filtré par nom et paginé.
+ ///
+ /// Nombre de titres a passer.
+ /// Nombre de titre récupéré.
+ /// Nom du style.
+ /// Une liste de titre.
+ IEnumerable SearchByStylePaginate(int offset, int limit, string libelle);
+
+ ///
+ /// Compter le nombre de titres au sein d'un style.
+ ///
+ /// Style de la musique.
+ /// Un entier.
+ int CountByStyle(string libelle);
+
///
/// Met à jour un titre dans la liste des titres en fonction de son identifiant. Si aucun titre correspondant à l'identifiant du titre fourni n'est trouvé, un message d'avertissement est enregistré dans les logs et aucune mise à jour n'est effectuée.
///
diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs
index ae14698..752e6b1 100644
--- a/Webzine.Repository/DbTitreRepository.cs
+++ b/Webzine.Repository/DbTitreRepository.cs
@@ -314,6 +314,20 @@ public class DbTitreRepository : ITitreRepository
}
}
+ ///
+ public IEnumerable SearchByStylePaginate(int offset, int limit, string libelle)
+ {
+ return this.SearchByStyle(libelle).Paginate(offset, limit);
+ }
+
+ ///
+ public int CountByStyle(string libelle)
+ {
+ return this.context.Titres
+ .Where(t => t.Styles.Any(s => s.Libelle.ToLower() == libelle.ToLower()))
+ .Count();
+ }
+
///
public int CountLike()
{
diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs
index cb9877f..0f5257b 100644
--- a/Webzine.Repository/LocalTitreRepository.cs
+++ b/Webzine.Repository/LocalTitreRepository.cs
@@ -112,6 +112,20 @@ public class LocalTitreRepository : ITitreRepository
.Where(t => t.Styles.Any(s => s.Libelle == libelle));
}
+ ///
+ public IEnumerable SearchByStylePaginate(int offset, int limit, string libelle)
+ {
+ return this.SearchByStyle(libelle).Paginate(offset, limit);
+ }
+
+ ///
+ public int CountByStyle(string libelle)
+ {
+ return this.dataStore.Titres
+ .Where(t => t.Styles.Any(s => s.Libelle == libelle))
+ .Count();
+ }
+
///
public void Update(Titre titre)
{
diff --git a/Webzine.WebApplication/Controllers/TitreController.cs b/Webzine.WebApplication/Controllers/TitreController.cs
index 9aefe66..27a0329 100644
--- a/Webzine.WebApplication/Controllers/TitreController.cs
+++ b/Webzine.WebApplication/Controllers/TitreController.cs
@@ -67,17 +67,25 @@ namespace Webzine.WebApplication.Controllers
/// Affiche les titres correspondant a un style musical donne.
///
/// Nom du style musical.
+ /// Numéro de la page.
/// Vue contenant la liste filtree.
- public IActionResult Style(string style)
+ [Route("/titres/styles/{style}", Name = "TitresParStyle")]
+ public IActionResult Style(string style, int page = 0)
{
- this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
+ var offset = page * 10;
+ var limit = 10;
+ var titresFiltres = this.titreRepository.SearchByStylePaginate(offset, limit, style).ToList();
+ var totalTitres = this.titreRepository.CountByStyle(style);
+ var totalPages = (int)Math.Ceiling((double)totalTitres / limit);
- var titresFiltres = this.titreRepository.SearchByStyle(style).ToList();
+ this.logger.LogInformation("Recherche des titres pour le style : {Style}.", style);
var vm = new TitreStyle
{
StyleName = style,
Titres = titresFiltres.Select(MapTitreItem).ToList(),
+ Page = page,
+ TotalPages = totalPages,
};
return this.View(vm);
diff --git a/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs b/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs
index 10c8a45..319bc5b 100644
--- a/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs
+++ b/Webzine.WebApplication/ViewModels/Titre/TitreStyle.cs
@@ -14,4 +14,14 @@ public class TitreStyle
/// Définit la liste des items de titre associés au style musical.
///
public List Titres { get; set; } = new ();
+
+ ///
+ /// Obtient ou définit le numéro de page pour la pagination des titres affichés sur la page d'accueil.
+ ///
+ public int Page { get; set; }
+
+ ///
+ /// Nombre total de page.
+ ///
+ public int TotalPages { get; set; }
}
\ No newline at end of file
diff --git a/Webzine.WebApplication/Views/Titre/Style.cshtml b/Webzine.WebApplication/Views/Titre/Style.cshtml
index 6970347..1c308b9 100644
--- a/Webzine.WebApplication/Views/Titre/Style.cshtml
+++ b/Webzine.WebApplication/Views/Titre/Style.cshtml
@@ -29,7 +29,7 @@
-
+
@@ -55,6 +55,39 @@
}
}
+