private SearchPaginationViewModel BuildPaginationForSearchResults( ProductSearchResult searchResult, TParam searchParam, int maxPages) { var totalCount = searchResult.TotalCount; var itemsPerPage = SearchConfiguration.MaxItemsPerPage; var totalPages = (int)Math.Ceiling((double)totalCount / itemsPerPage); var param = new CreateSearchPaginationParam <TParam> { SearchParameters = searchParam, CurrentPageIndex = searchParam.Criteria.Page, MaximumPages = SearchConfiguration.ShowAllPages ? totalPages : maxPages, TotalNumberOfPages = totalPages, CorrectedSearchTerms = searchResult.CorrectedSearchTerms }; var pages = GetPages(param); var pager = new SearchPaginationViewModel { PreviousPage = GetPreviousPage(param), NextPage = GetNextPage(param), CurrentPage = pages.FirstOrDefault(p => p.IsCurrentPage), Pages = pages, TotalNumberOfPages = totalPages }; return(pager); }
/**********private methods**********/ private SearchPaginationViewModel Get_SearchPagination_Params(Controller ctrl) { SearchPaginationViewModel params_search_pagination = new SearchPaginationViewModel() { page = ctrl.TempData["page"] == null ? 1 : Int32.Parse(ctrl.TempData["page"].ToString()), filter = ctrl.TempData["filter"] == null ? "" : ctrl.TempData["filter"].ToString() }; return(params_search_pagination); }
// GET: Admin/ArtGallery public ActionResult Index(int?page, string filter) { SearchPaginationViewModel search_vm = new SearchPaginationViewModel() { filter = filter + "", page = page.HasValue ? page.Value : 1 }; GalleryPageViewModel page_vm = NegahenoService.Get_Index_ArtGallery(search_vm, this); if (Request.IsAjaxRequest()) { return(PartialView("_PartialGalleryList", page_vm.paged_list_artGallery)); } else { return(View(page_vm)); } }
public GalleryPageViewModel Get_Index_ArtGallery(SearchPaginationViewModel search_pagination_vm, Controller ctrl) { ctrl.TempData["page"] = search_pagination_vm.page; ctrl.TempData["filter"] = search_pagination_vm.filter; GalleryPageViewModel page_vm = new GalleryPageViewModel(); IPagedList <ArtGalleryViewModel> paged_list_artGallery = null; List <ArtGalleryViewModel> lst_gallery = DataLayer.Get_ArtGalleryList(); if (lst_gallery != null) { lst_gallery = FilterGalleryList(lst_gallery, search_pagination_vm.filter); lst_gallery = lst_gallery.OrderBy(x => x.fromDate).Select((x, Index) => new ArtGalleryViewModel() { rowNumber = Index + 1, GalleryId = x.GalleryId, fa_title = x.fa_title, description = x.description, fromDate = x.fromDate, toDate = x.toDate, fromHour = x.fromHour, toHour = x.toHour }).ToList(); int currentpage = search_pagination_vm.page.HasValue ? search_pagination_vm.page.Value : 1; paged_list_artGallery = lst_gallery.ToPagedList(currentpage, pagesize); } page_vm.paged_list_artGallery = paged_list_artGallery; page_vm.search_pagination_params = search_pagination_vm; return(page_vm); }