public static MatchIndexViewMode MapFromMatchIndex(this IEnumerable <MatchViewModel> matches, int currentPage, int totalPages) { var model = new MatchIndexViewMode { Matches = matches, CurrentPage = currentPage, TotalPages = totalPages, }; return(model); }
public async Task <IActionResult> Index(int?currentPage, string search = null) { try { //string userId = FindCurrentUserId(); int currPage = currentPage ?? 1; int totalPages = await _matchServices.GetPageCount(10); IEnumerable <Match> allMatches = null; if (!string.IsNullOrEmpty(search)) { allMatches = await _matchServices.SearchMatch(search, currPage); } else { allMatches = await _matchServices.GetAllMatchesAsync(currPage); } IEnumerable <MatchViewModel> matchListing = allMatches .Select(m => MatchMapper.MapMatch(m)); MatchIndexViewMode matchVM = MatchMapper.MapFromMatchIndex(matchListing, currPage, totalPages); #region For pagination buttons and distribution matchVM.CurrentPage = currPage; matchVM.TotalPages = totalPages; if (totalPages > currPage) { matchVM.NextPage = currPage + 1; } if (currPage > 1) { matchVM.PreviousPage = currPage - 1; } #endregion return(View(matchVM)); } catch (GlobalException e) { return(BadRequest(e.Message)); } }