public void SetupViewModelPaging(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string resultsPage, int recordsPerPage) { if (viewModel != null && response != null) { if (response.ResultProperties.Page == 0) { response.ResultProperties.Page = 1; } viewModel.Count = recordsPerPage; viewModel.Page = response.ResultProperties.Page; viewModel.ResultProperties = response.ResultProperties; if (viewModel.ResultProperties.TotalPages > 1 && viewModel.ResultProperties.TotalPages >= viewModel.ResultProperties.Page) { var partialQueryString = context.GetQueryStringExcluding(new[] { $"{nameof(CourseSearchProperties.Page)}" }); viewModel.PaginationViewModel.HasPreviousPage = viewModel.ResultProperties.Page > 1; viewModel.PaginationViewModel.HasNextPage = viewModel.ResultProperties.Page < viewModel.ResultProperties.TotalPages; viewModel.PaginationViewModel.NextPageUrl = new Uri($"{resultsPage}?{partialQueryString}&{nameof(CourseSearchProperties.Page)}={viewModel.ResultProperties.Page + 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.NextPageText = $"{viewModel.ResultProperties.Page + 1} of {viewModel.ResultProperties.TotalPages}"; if (viewModel.ResultProperties.Page > 1) { viewModel.PaginationViewModel.PreviousPageUrl = new Uri($"{resultsPage}?{partialQueryString}&{nameof(CourseSearchProperties.Page)}={viewModel.ResultProperties.Page - 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.PreviousPageText = $"{viewModel.ResultProperties.Page - 1} of {viewModel.ResultProperties.TotalPages}"; } } } }
public void SetupPaging(CourseSearchResultsViewModel viewModel, CourseSearchResult response, string pathQuery, int recordsPerPage, string courseSearchResultsPage) { if (viewModel != null && response != null) { viewModel.Count = recordsPerPage; viewModel.Page = response.ResultProperties.Page; viewModel.ResultProperties = response.ResultProperties; if (viewModel.ResultProperties.TotalPages > 1 && viewModel.ResultProperties.TotalPages >= viewModel.ResultProperties.Page) { viewModel.PaginationViewModel.HasPreviousPage = viewModel.ResultProperties.Page > 1; viewModel.PaginationViewModel.HasNextPage = viewModel.ResultProperties.Page < viewModel.ResultProperties.TotalPages; viewModel.PaginationViewModel.NextPageUrl = new Uri( $"{pathQuery}&page={viewModel.ResultProperties.Page + 1}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.NextPageText = $"{viewModel.ResultProperties.Page + 1} of {viewModel.ResultProperties.TotalPages}"; if (viewModel.ResultProperties.Page > 1) { viewModel.PaginationViewModel.PreviousPageUrl = new Uri( $"{pathQuery}{(viewModel.ResultProperties.Page == 2 ? string.Empty : $"&page={viewModel.ResultProperties.Page - 1}")}", UriKind.RelativeOrAbsolute); viewModel.PaginationViewModel.PreviousPageText = $"{viewModel.ResultProperties.Page - 1} of {viewModel.ResultProperties.TotalPages}"; } } }