public void AddTeamDetailToSeason(Team team, int season) { var teamDetail = new TeamsDetails { SeasonId = season, TeamId = team.TeamId, TeamName = team.Title }; db.TeamsDetails.Add(teamDetail); db.SaveChanges(); }
public TeamCompactViewModel(Team team, int leagueId, int?seasonId = null) { TeamId = team.TeamId; LeagueId = leagueId; Logo = team.Logo; if (seasonId.HasValue) { TeamsDetails teamsDetails = team.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasonId); Title = teamsDetails != null ? teamsDetails.TeamName : team.Title; } else { Title = team.Title; } }
internal static TeamInfoViewModel GetTeamInfo(Team team, int leagueId, int?seasonId = null) { if (!team.LeagueTeams.Any(l => l.LeagueId == leagueId)) { return(null); } var vm = new TeamInfoViewModel(); //teamId vm.TeamId = team.TeamId; //"place": 7, //"ratio": "2:3", //"succsessLevel": 59, LeagueRankService leagueRankService = new LeagueRankService(leagueId); RankLeague rLeague = leagueRankService.CreateLeagueRankTable(seasonId); if (rLeague != null) { var stage = rLeague.Stages.OrderByDescending(t => t.Number).FirstOrDefault(); RankGroup group; if (stage != null) { group = stage.Groups.Where(gr => gr.Teams.Any(t => t.Id == team.TeamId)).FirstOrDefault(); RankTeam rTeam = null; if (group != null) { rTeam = group.Teams.Where(t => t.Id == team.TeamId).FirstOrDefault(); } if (rTeam != null) { vm.Place = int.Parse(rTeam.Position); vm.Ratio = rTeam.SetsLost.ToString() + ":" + rTeam.SetsWon.ToString(); if (rTeam.Games == 0) { vm.SuccsessLevel = 0; } else { double wins = rTeam.Wins; double games = rTeam.Games; double ratio = (wins / games) * 100; vm.SuccsessLevel = Convert.ToInt32(ratio); } } } } vm.Logo = team.Logo; vm.Image = team.PersonnelPic; vm.League = team.LeagueTeams.Where(tl => tl.LeagueId == leagueId).FirstOrDefault().Leagues.Name; vm.LeagueId = leagueId; if (seasonId.HasValue) { TeamsDetails teamsDetails = team.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasonId); vm.Title = teamsDetails != null ? teamsDetails.TeamName : team.Title; } else { vm.Title = team.Title; } return(vm); }
internal static GameViewModel ParseGameCycle(GamesCycle gameCycle, int?seasondId = null) { if (gameCycle != null) { int typePlayOff = 2; if (gameCycle.PlayoffBracket != null) { typePlayOff = gameCycle.PlayoffBracket.Type; } var gameModel = new GameViewModel { HouseName = gameCycle.Group != null ? gameCycle.Group.Name : "", GroupName = gameCycle.Auditorium != null ? gameCycle.Auditorium.Name : "", GameId = gameCycle.CycleId, GameCycleStatus = gameCycle.GameStatus ?? "next", StartDate = gameCycle.StartDate, HomeTeamId = gameCycle.HomeTeamId, HomeTeam = !gameCycle.HomeTeamId.HasValue ? (typePlayOff == 2 ? "Winner" : "Loser") : gameCycle.HomeTeam.Title, HomeTeamScore = gameCycle.HomeTeamScore, GuestTeam = !gameCycle.GuestTeamId.HasValue ? (typePlayOff == 2 ? "Winner" : "Loser") : gameCycle.GuestTeam.Title, GuestTeamId = gameCycle.GuestTeamId, GuestTeamScore = gameCycle.GuestTeamScore, Auditorium = gameCycle.Auditorium != null ? gameCycle.Auditorium.Name : null, HomeTeamLogo = gameCycle.HomeTeam != null ? gameCycle.HomeTeam.Logo : string.Empty, GuestTeamLogo = gameCycle.GuestTeam != null ? gameCycle.GuestTeam.Logo : string.Empty, CycleNumber = gameCycle.CycleNum, MaxPlayoffPos = gameCycle.MaxPlayoffPos, MinPlayoffPos = gameCycle.MinPlayoffPos }; var alias = gameCycle?.Stage?.League?.Union?.Section?.Alias; switch (alias) { case GamesAlias.WaterPolo: case GamesAlias.BasketBall: if (gameCycle.GameSets.Any()) { gameModel.HomeTeamScore = gameCycle.GameSets.Sum(x => x.HomeTeamScore); gameModel.GuestTeamScore = gameCycle.GameSets.Sum(x => x.GuestTeamScore); } break; } if (gameCycle.Group != null && gameCycle.Group.IsAdvanced && gameCycle.Group.PlayoffBrackets != null) { int numOfBrackets = gameCycle.Group.PlayoffBrackets.Count; switch (numOfBrackets) { case 1: gameModel.PlayOffType = Messages.Final; break; case 2: gameModel.PlayOffType = Messages.Semifinals; break; case 4: gameModel.PlayOffType = Messages.Quarter_finals; break; case 8: gameModel.PlayOffType = Messages.Final_Eighth; break; default: gameModel.PlayOffType = (numOfBrackets * 2) + " " + Messages.FinalNumber; break; } } if (seasondId.HasValue && gameCycle.GuestTeam != null && gameCycle.HomeTeam != null) { TeamsDetails homeTeamsDetails = gameCycle.HomeTeam.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasondId); gameModel.HomeTeam = homeTeamsDetails != null ? homeTeamsDetails.TeamName : gameCycle.HomeTeam.Title; TeamsDetails guestTeamsDetails = gameCycle.GuestTeam.TeamsDetails.FirstOrDefault(x => x.SeasonId == seasondId); gameModel.GuestTeam = guestTeamsDetails != null ? guestTeamsDetails.TeamName : gameCycle.GuestTeam.Title; } else { gameModel.HomeTeam = !gameCycle.HomeTeamId.HasValue ? (typePlayOff == 2 ? "Winner" : "Loser") : gameCycle.HomeTeam.Title; gameModel.GuestTeam = !gameCycle.GuestTeamId.HasValue ? (typePlayOff == 2 ? "Winner" : "Loser") : gameCycle.GuestTeam.Title; } return(gameModel); } return(null); }