Exemple #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));
        }