public async Task <TorrentsViewModel> GetTorrents(int pageIndex, int itemsPage, string searchText) { var filterSpecification = new CatalogFilterSpecification(searchText); var filterPaginatedSpecification = new CatalogFilterPaginatedSpecification(itemsPage * pageIndex, itemsPage, searchText); var torrentsOnPage = await _torrentRepository.ListAsync(filterPaginatedSpecification); var totalTorrents = await _torrentRepository.CountAsync(filterSpecification); var ci = new TorrentsViewModel { CatalogTorrents = torrentsOnPage.Select(x => new TorrentViewModel() { Id = x.Id, Title = x.Title, Size = x.Size, RegistredAt = x.RegistredAt }), SearchText = searchText, PaginationInfo = new PaginationInfoViewModel() { ActualPage = pageIndex, TorrentsPerPage = torrentsOnPage.Count, TotalTorrents = totalTorrents, TotalPages = int.Parse(Math.Ceiling((decimal)totalTorrents / itemsPage).ToString()) } }; ci.PaginationInfo.Previous = (ci.PaginationInfo.ActualPage == 0) ? "is-disabled" : ""; ci.PaginationInfo.Next = (ci.PaginationInfo.ActualPage == ci.PaginationInfo.TotalPages - 1) ? "is-disabled" : ""; return(ci); }
public ClientViewModel(TorrentsViewModel torrents) { _torrents = torrents; }
public async Task OnGet(TorrentsViewModel catalogModel, int?pageId) { CatalogModel = await _catalogViewModelService.GetTorrents(pageId ?? 0, Constants.ITEMS_PER_PAGE, catalogModel.SearchText); }