diff --git a/Webzine.Repository.Contracts/ITitreRepository.cs b/Webzine.Repository.Contracts/ITitreRepository.cs
index 8c574c1..4f19c38 100644
--- a/Webzine.Repository.Contracts/ITitreRepository.cs
+++ b/Webzine.Repository.Contracts/ITitreRepository.cs
@@ -107,5 +107,19 @@
///
/// Un tuple contenant l'identifiant et le libellé du titre le plus joué, ou null si aucun titre n'existe.
(int IdTitre, string Libelle)? FindMostPlayedTitle();
+
+ ///
+ /// Récupération des chroniques.
+ ///
+ /// Nombre d'éléments.
+ /// Limite d'éléments.
+ /// Liste des derniers titres chroniqués.
+ IEnumerable DerniereChronique(int offset, int limit);
+
+ ///
+ /// Récupération du top titre liké.
+ ///
+ /// Liste de titre les plus likés.
+ IEnumerable TopTitre(int offset, int limit);
}
}
\ No newline at end of file
diff --git a/Webzine.Repository/DbTitreRepository.cs b/Webzine.Repository/DbTitreRepository.cs
index 37ecdb0..a581fe9 100644
--- a/Webzine.Repository/DbTitreRepository.cs
+++ b/Webzine.Repository/DbTitreRepository.cs
@@ -409,4 +409,45 @@ public class DbTitreRepository : ITitreRepository
throw;
}
}
+
+ ///
+ public IEnumerable DerniereChronique(int offset, int limit)
+ {
+ try
+ {
+ this.logger.LogInformation("Récupération des dernières chroniques.");
+
+ return this.context.Titres
+ .AsNoTracking()
+ .OrderByDescending(t => t.DateCreation)
+ .Paginate(offset, limit)
+ .Include(t => t.Artiste);
+ }
+ catch (Exception ex)
+ {
+ this.logger.LogError(ex, "Erreur lors de la recuperation des dernieres chroniques.");
+ throw;
+ }
+ }
+
+ ///
+ public IEnumerable TopTitre(int offset, int limit)
+ {
+ try
+ {
+ this.logger.LogInformation("Récupération du Top Titre.");
+ var titres = this.context.Titres
+ .AsNoTracking()
+ .OrderByDescending(t => t.NbLikes)
+ .Paginate(offset, limit)
+ .Include(a => a.Artiste);
+
+ return titres;
+ }
+ catch (Exception ex)
+ {
+ this.logger.LogError(ex, "Erreur lors de la récupération du Top Titre.");
+ throw;
+ }
+ }
}
\ No newline at end of file
diff --git a/Webzine.Repository/LocalTitreRepository.cs b/Webzine.Repository/LocalTitreRepository.cs
index 13e995e..cb9877f 100644
--- a/Webzine.Repository/LocalTitreRepository.cs
+++ b/Webzine.Repository/LocalTitreRepository.cs
@@ -181,4 +181,39 @@ public class LocalTitreRepository : ITitreRepository
return titre == null ? null : (titre.IdTitre, titre.Libelle);
}
+
+ ///
+ public IEnumerable DerniereChronique(int offset, int limit)
+ {
+ try
+ {
+ return this.dataStore.Titres
+ .OrderByDescending(t => t.DateCreation)
+ .Paginate(offset, limit);
+ }
+ catch (Exception ex)
+ {
+ this.logger.LogError(ex, "Erreur lors de la recuperation des dernieres chroniques.");
+ throw;
+ }
+ }
+
+ ///
+ public IEnumerable TopTitre(int offset, int limit)
+ {
+ try
+ {
+ this.logger.LogInformation("Récupération du Top Titre.");
+ var titres = this.dataStore.Titres
+ .OrderByDescending(t => t.NbLikes)
+ .Paginate(offset, limit);
+
+ return titres;
+ }
+ catch (Exception ex)
+ {
+ this.logger.LogError(ex, "Erreur lors de la récupération du Top Titre.");
+ throw;
+ }
+ }
}
\ No newline at end of file
diff --git a/Webzine.WebApplication/Controllers/AccueilController.cs b/Webzine.WebApplication/Controllers/AccueilController.cs
index fd7c03e..f7832da 100644
--- a/Webzine.WebApplication/Controllers/AccueilController.cs
+++ b/Webzine.WebApplication/Controllers/AccueilController.cs
@@ -47,15 +47,13 @@
var totalTitres = this.titreRepository.Count();
var totalPages = (int)Math.Ceiling((double)totalTitres / derniereChronique);
- var titresPagines = this.titreRepository.FindTitres(page * derniereChronique, derniereChronique);
- var topTitres = this.titreRepository.FindAll()
- .OrderByDescending(t => t.NbLikes)
- .Take(nbTopTitres);
+ var titresPagines = this.titreRepository.DerniereChronique(page * derniereChronique, derniereChronique).ToList();
+ var topTitres = this.titreRepository.TopTitre(nbTopTitres, nbTopTitres).ToList();
var vm = new AccueilIndexViewModel
{
- DerniersTitres = titresPagines.ToList(),
- TopTitres = topTitres.ToList(),
+ DerniersTitres = titresPagines,
+ TopTitres = topTitres,
Page = page,
TotalPages = totalPages,
};