public static TeamIndexViewMode MapFromTeamIndex(this IEnumerable <TeamViewModel> team,
                                                         int currentPage, int totalPages)
        {
            var teamModel = new TeamIndexViewMode
            {
                Teams       = team,
                CurrentPage = currentPage,
                TotalPages  = totalPages,
            };

            return(teamModel);
        }
        public async Task <IActionResult> Index(int?currentPage, string search = null)
        {
            try
            {
                //string userId = FindCurrentUserId();

                int currPage   = currentPage ?? 1;
                int totalPages = await _teamServices.GetPageCount(10);

                IEnumerable <Team> allTeams = null;

                if (!string.IsNullOrEmpty(search))
                {
                    allTeams = await _teamServices.SearchTeam(search, currPage);
                }
                else
                {
                    allTeams = await _teamServices.GetAllTeamsAsync(currPage);
                }

                IEnumerable <TeamViewModel> teamListing = allTeams
                                                          .Select(m => TeamMapper.MapTeam(m));
                TeamIndexViewMode teamVM = TeamMapper.MapFromTeamIndex(teamListing,
                                                                       currPage, totalPages);

                #region For pagination buttons and distribution
                teamVM.CurrentPage = currPage;
                teamVM.TotalPages  = totalPages;

                if (totalPages > currPage)
                {
                    teamVM.NextPage = currPage + 1;
                }

                if (currPage > 1)
                {
                    teamVM.PreviousPage = currPage - 1;
                }
                #endregion

                return(View(teamVM));
            }
            catch (GlobalException e)
            {
                return(BadRequest(e.Message));
            }
        }