public async Task <IActionResult> Edit(int id)
        {
            Team team = await _teamServices.GetTeamAsync(id);

            TeamViewModel mapTeam = TeamMapper.MapTeam(team);

            return(View("Edit", mapTeam));
        }
        public async Task <IActionResult> Create(TeamViewModel viewModel)
        {
            try
            {
                Team mapTeam = TeamMapper.MapTeam(viewModel);
                Team team    = await _teamServices.CreateTeamAsync(mapTeam);

                return(RedirectToAction("Index", new { id = team.TeamId }));
            }
            catch (GlobalException e)
            {
                return(BadRequest(e.Message));
            }
        }
        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));
            }
        }
Exemplo n.º 4
0
        private static void AddMatchData(List <Match> matches, RiotDataContext riotDb)
        {
            Console.WriteLine("Updating {0} matches.", matches.Count());

            foreach (var match in matches)
            {
                var matchData    = RiotService.MatchService(match.MatchId);
                var currentMatch = riotDb.Matches.First(m => m.MatchId == match.MatchId);
                currentMatch.AddMatchData(matchData);

                foreach (var participant in matchData.Participants)
                {
                    var stats = StatisticsMapper.MapParticipantStat(participant.Statistics);
                    currentMatch.Participants.Add(ParticipantMapper.MapParticipant(matchData, participant, stats));
                }

                foreach (var team in matchData.Teams)
                {
                    currentMatch.Teams.Add(TeamMapper.MapTeam(team));
                }

                riotDb.SubmitChanges();
            }
        }