#192 Pagination des pages admin. On peut passer à la page précédente seulement si le numéro de page est >0 et la dernière page n'affiche pas de bouton pour la page suivante.
This commit is contained in:
@@ -13,6 +13,7 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
{
|
||||
private readonly ILogger<CommentaireController> logger;
|
||||
private readonly ICommentaireRepository commentaireRepository;
|
||||
private readonly IConfiguration configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CommentaireController"/> class.
|
||||
@@ -21,10 +22,15 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
/// </summary>
|
||||
/// <param name="logger">Service de journalisation injecté.</param>
|
||||
/// <param name="commentaireRepository">Le repository des commentaires injecté.</param>
|
||||
public CommentaireController(ILogger<CommentaireController> logger, ICommentaireRepository commentaireRepository)
|
||||
/// <param name="configuration">Service de configuration injecté pour accéder aux paramètres de configuration.</param>
|
||||
public CommentaireController(
|
||||
ILogger<CommentaireController> logger,
|
||||
ICommentaireRepository commentaireRepository,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.commentaireRepository = commentaireRepository;
|
||||
this.configuration = configuration;
|
||||
|
||||
this.logger.LogInformation("Initialisation du contrôleur CommentaireController.");
|
||||
}
|
||||
@@ -32,16 +38,23 @@ namespace Webzine.WebApplication.Areas.Administration.Controllers
|
||||
/// <summary>
|
||||
/// Affiche la liste des commentaires dans la vue Index.
|
||||
/// </summary>
|
||||
/// <param name="page">Le numéro de page pour la pagination des commentaires (par défaut à 0).</param>
|
||||
/// <returns>La vue Index avec le ViewModel contenant la liste des commentaires.</returns>
|
||||
public IActionResult Index()
|
||||
public IActionResult Index(int page = 0)
|
||||
{
|
||||
int commentaires_par_page = this.configuration.GetValue<int>("Webzine:NombreDeLignesAdministration");
|
||||
|
||||
// Récupération des commentaires depuis le repository
|
||||
var commentaires = this.commentaireRepository.FindAll();
|
||||
var commentaires = this.commentaireRepository.FindCommentaires(page * commentaires_par_page, commentaires_par_page);
|
||||
|
||||
int totalCommentaires = this.commentaireRepository.Count();
|
||||
|
||||
// Initialisation du ViewModel
|
||||
var viewModel = new CommentaireViewModel
|
||||
var viewModel = new CommentaireIndexViewModel
|
||||
{
|
||||
Commentaires = commentaires,
|
||||
Page = page,
|
||||
TotalPages = (int)Math.Ceiling((double)totalCommentaires / commentaires_par_page),
|
||||
};
|
||||
|
||||
return this.View(viewModel);
|
||||
|
||||
Reference in New Issue
Block a user