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 644febd..f7832da 100644 --- a/Webzine.WebApplication/Controllers/AccueilController.cs +++ b/Webzine.WebApplication/Controllers/AccueilController.cs @@ -31,7 +31,6 @@ this.configuration = configuration; this.titreRepository = titreRepository; this.logger.LogDebug(1, "initialisation du AccueilController"); - this.titreRepository = titreRepository; } /// @@ -45,17 +44,18 @@ var derniereChronique = this.configuration.GetValue("Webzine:NombreDerniereChronique"); var nbTopTitres = this.configuration.GetValue("Webzine:NombreDeTopTitres"); + var totalTitres = this.titreRepository.Count(); + var totalPages = (int)Math.Ceiling((double)totalTitres / derniereChronique); - var titres_pagines = this.titreRepository.FindTitres(page * derniereChronique, derniereChronique); - var top_titres = 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 = titres_pagines.ToList(), - TopTitres = top_titres.ToList(), + DerniersTitres = titresPagines, + TopTitres = topTitres, Page = page, + TotalPages = totalPages, }; return this.View(vm); diff --git a/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs b/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs index dbf66ff..d08b1a1 100644 --- a/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs +++ b/Webzine.WebApplication/ViewModels/Accueil/AccueilIndexViewModel.cs @@ -26,5 +26,10 @@ /// 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; } = 0; + + /// + /// Nombre total de page. + /// + public int TotalPages { get; set; } = 0; } } \ No newline at end of file diff --git a/Webzine.WebApplication/Views/Accueil/Index.cshtml b/Webzine.WebApplication/Views/Accueil/Index.cshtml index 82710cf..96769fd 100644 --- a/Webzine.WebApplication/Views/Accueil/Index.cshtml +++ b/Webzine.WebApplication/Views/Accueil/Index.cshtml @@ -73,12 +73,21 @@ } -
- - Titres plus anciens >> - - +
+ @if (Model.Page > 0) + { + + << Titre plus récent + + } + @if (Model.Page < Model.TotalPages - 1) + { + + Titre plus anciens >> + + }
diff --git a/Webzine.WebApplication/Views/Contact/Index.cshtml b/Webzine.WebApplication/Views/Contact/Index.cshtml index 55ef4d4..a66aefc 100644 --- a/Webzine.WebApplication/Views/Contact/Index.cshtml +++ b/Webzine.WebApplication/Views/Contact/Index.cshtml @@ -11,8 +11,8 @@
- Phone : 03 80 40 50 60
- secretariat@cucdb.fr + Phone : 03 80 40 50 60
+ secretariat@cucdb.fr
@@ -22,35 +22,35 @@

Suivez-nous