Esempio n. 1
0
        //[ResponseType(typeof(FanOwnPrfileViewModel))]
        public IHttpActionResult GetFanHomePage(int teamId, int leagueId)
        {
            User user = CurrentUser;

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

            Team team = db.Teams.Find(teamId);

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

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

            int?seasonId = _seasonsRepo.GetLastSeasonByLeagueId(leagueId);

            var vm = new FanOwnPrfileViewModel();

            vm.TeamInfo = TeamsService.GetTeamInfo(team, leagueId);

            var teamGames = team.GuestTeamGamesCycles
                            .Concat(team.HomeTeamGamesCycles)
                            .Where(tg => tg.Stage.LeagueId == leagueId && tg.IsPublished)
                            .ToList();

            //Next Game
            vm.NextGame = GamesService.GetNextGame(teamGames, Convert.ToInt32(User.Identity.Name), leagueId, seasonId);
            //Last Game
            vm.LastGame = GamesService.GetLastGame(teamGames, seasonId);
            //Team Fans
            vm.TeamFans = TeamsService.GetTeamFans(team.TeamId, leagueId, CurrentUser.UserId);
            //Friends
            vm.Friends = FriendsService.GetAllConfirmedFriendsAsUsers(user).Select(u =>
                                                                                   new FanFriendViewModel
            {
                Id               = u.UserId,
                UserName         = u.UserName,
                FullName         = u.FullName,
                UserRole         = u.UsersType.TypeRole,
                Image            = u.Image,
                CanRcvMsg        = true,
                FriendshipStatus = FriendshipStatus.Yes,
                Teams            = TeamsService.GetFanTeams(u)
            }).Where(u => u.Id != this.CurrUserId).ToList();

            return(Ok(vm));
        }
Esempio n. 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));
            }
        }