예제 #1
0
        public IHttpActionResult Get(int id, int?unionId = null, int?leagueId = null)
        {
            User player = db.Users.FirstOrDefault(u => u.UserId == id && u.IsArchive == false && u.IsActive);

            if (player == null)
            {
                return(NotFound());
            }

            if (unionId == null && leagueId != null)
            {
                LeagueRepo leagueRepo = new LeagueRepo();
                League     league     = leagueRepo.GetById((int)leagueId);
                unionId = league != null ? league.UnionId : null;
            }
            int?seasonId = unionId != null?_seasonsRepo.GetLastSeasonByCurrentUnionId(unionId.Value) : (int?)null;

            PlayerProfileViewModel vm = PlayerService.GetPlayerProfile(player);

            var teamsRepo = new TeamsRepo();

            vm.Teams = teamsRepo.GetPlayerPositions(id, seasonId);

            vm.FriendshipStatus = FriendsService.AreFriends(id, CurrUserId);

            if (User.Identity.IsAuthenticated)
            {
                vm.Friends = FriendsService.GetAllFanFriends(id, base.CurrUserId);
            }

            vm.Games = GamesService.GetPlayerGames(player.UserId, seasonId);

            GamesService.UpdateGameSets(vm.Games);

            return(Ok(vm));
        }
예제 #2
0
        public IHttpActionResult GetTeam(int teamId, int leagueId)
        {
            try
            {
                var team = teamsService.GetTeamById(teamId);
                if (team == null)
                {
                    return(NotFound());
                }

                TeamPageViewModel vm = new TeamPageViewModel();
                if (!team.LeagueTeams.Any(l => l.LeagueId == leagueId))
                {
                    return(NotFound());
                }

                vm.TeamInfo = TeamsService.GetTeamInfo(team, leagueId);
                if (vm.TeamInfo == null)
                {
                    return(NotFound());
                }

                var section = sectionsRepo.GetByLeagueId(leagueId);

                int?currentSeasonId = seasonsRepo.GetLastSeasonByLeagueId(leagueId);

                var teamGames = team.GuestTeamGamesCycles
                                .Concat(team.HomeTeamGamesCycles)
                                .Where(tg => tg.Stage.LeagueId == leagueId && tg.IsPublished).ToList();
                int currentUserId = Convert.ToInt32(User.Identity.Name);

                GamesService.UpdateGameSets(teamGames, section: section?.Alias);
                //Next Game
                vm.NextGame = GamesService.GetNextGame(teamGames, currentUserId, leagueId, currentSeasonId);
                //List of all next games
                vm.NextGames = GamesService.GeTeamNextGames(leagueId, teamId, DateTime.Now, currentSeasonId);
                //Last Game
                vm.LastGame = GamesService.GetLastGame(teamGames, currentSeasonId);
                //Last Games
                vm.LastGames = GamesService.GetLastGames(teamGames, currentSeasonId).OrderBy(x => x.StartDate);
                //League Info
                var leagues = leagueRepo.GetLastSeasonLeaguesBySection(section.SectionId)
                              .Where(l => db.LeagueTeams.Where(lt => lt.TeamId == team.TeamId).Select(lt => lt.LeagueId).Contains(l.LeagueId))
                              .ToList();
                vm.Leagues = leagues.Select(l => new LeagueInfoVeiwModel(l)).ToList();
                //Fans
                vm.Fans = TeamsService.GetTeamFans(team.TeamId, leagueId, CurrentUser.UserId);
                //Game Cycles
                vm.GameCycles = teamGames.Select(gc => gc.CycleNum).Distinct().OrderBy(c => c).ToList();
                //Players
                vm.Players = currentSeasonId != null?PlayerService.GetActivePlayersByTeamId(teamId, currentSeasonId.Value) :
                                 new List <CompactPlayerViewModel>();

                // Set friends status for each of the players
                FriendsService.AreFriends(vm.Players, currentUserId);
                //Jobs
                vm.Jobs = TeamsService.GetTeamJobsByTeamId(teamId, currentUserId);

                vm.MessageThreads = MessagesService.GetTeamMessages(teamId);

                return(Ok(vm));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }