public static PaginationViewModel CreatePagination(string action, string controller, IThesesSystemData data, int currentPage, int id = 0, FilterOptions options = null) { int pagesNumber = 0; if (options == null) { pagesNumber = GetPages(data, controller + action, id); } else { pagesNumber = GetPages(data, controller + action, keyWord: options.KeyWord, filterBy: options.FilterBy); } var hasNextPage = currentPage != (pagesNumber - 1) && pagesNumber != 0; var hasPreviousPage = currentPage != 0; var pagination = new PaginationViewModel { CurrentPage = currentPage, PagesNumber = pagesNumber, HasNext = hasNextPage, HasPrevious = hasPreviousPage, Action = action, Controller = controller }; return pagination; }
public ActionResult Index(int? page, FilterOptions options) { int currentPage = page ?? 0; var theses = this.Data.Theses .All() .Where(u => u.IsComplete); if (options != null) { if (options.KeyWord != null) { theses = this.SetFilterClause(theses, options.FilterBy, options.KeyWord); } if (options.SortType == SortType.Ascending) { theses = this.SetSortAscendingClause(theses, options.SortBy); } else { theses = this.SetSortDescendingClause(theses, options.SortBy); } } else { theses = theses.OrderBy(t => t.FinishedAt); } var thesesViewModel = theses .Skip(GlobalConstants.ELEMENTS_PER_PAGE * currentPage) .Take(GlobalConstants.ELEMENTS_PER_PAGE) .Project() .To<ThesisViewModel>() .ToList(); ViewData["FilterOptions"] = options; ViewData["Pagination"] = PaginationHelper.CreatePagination("Index", "Storage", this.Data, currentPage, options: options); ViewData["IsKeyWordCorrect"] = this.isKeyWordCorrect; return View(thesesViewModel); }