Exemplo n.º 1
0
        public IActionResult Navigate(int id)
        {
            int lengthPage  = Int32.Parse(_configuration["lengthAdminPage"]);
            int displayPage = Int32.Parse(_configuration["displayAdminPage"]);
            int indexActuel = (id - 1) * lengthPage;

            _titres = _titreRepository.Take(indexActuel, (_titreRepository.Count() <= (id * lengthPage)) ? _titreRepository.Count() - indexActuel : lengthPage).Select(vm =>
                                                                                                                                                                       new TitresViewModel
            {
                IdTitre        = vm.IdTitre,
                IdArtiste      = vm.IdArtiste,
                NomTitre       = vm.Libelle,
                NbLectures     = vm.NbLectures,
                NbLikes        = vm.NbLikes,
                NomArtiste     = vm.Artiste.Nom,
                NbCommentaires = (vm.Commentaires != null) ? vm.Commentaires.Count : 0,
                Duree          = vm.Duree,
                DateSortie     = vm.DateSortie
            }).ToList();


            IndexTitresViewModel indextitresViewModel = new IndexTitresViewModel
            {
                Titres      = _titres,
                TotalTitres = _titreRepository.Count(),
                PageActuel  = id,
                LengthPage  = lengthPage,
                DisplayPage = displayPage,
                Next        = (_titreRepository.Count() - indexActuel > lengthPage) ? true : false
            };

            return(this.View(nameof(TitresController.Index), indextitresViewModel));
        }
 public IViewComponentResult Invoke(IndexTitresViewModel pagination)
 {
     return(View(pagination));
 }