private static void AddUserBetToListForGroup(TodaysGamesSpecification todaysGamesSpecification, Bet currentGamesBet, UserBetViewModel userBetViewModel) { var resultAsString = currentGamesBet.HomeGoals + "-" + currentGamesBet.AwayGoals; AddOrUpdateTodaysBet(todaysGamesSpecification, resultAsString, userBetViewModel); }
private static void SetTeamValuesForPlayoffGames(TodaysGamesSpecification todaysGamesSpecification, UserBet resultUserBet, List <Team> teams) { var playoffBet = resultUserBet?.PlayoffBets.FirstOrDefault(x => x.GameId == todaysGamesSpecification.Id); if (playoffBet == null) { SetValuesDefaultValuesForTeams(todaysGamesSpecification); } else { if (playoffBet.HomeTeam != null) { todaysGamesSpecification.HomeTeam = teams.FirstOrDefault(x => x.Id == playoffBet.HomeTeam); } else { SetDefaultValueForHomeTeam(todaysGamesSpecification); } if (playoffBet.AwayTeam != null) { todaysGamesSpecification.AwayTeam = teams.FirstOrDefault(x => x.Id == playoffBet.AwayTeam); } else { SetDefaultValueForAwayTeam(todaysGamesSpecification); } } }
private static void AddUserBetToExistingResult(TodaysGamesSpecification todaysGamesSpecification, string teamKey, UserBetViewModel userBetViewModel) { todaysGamesSpecification.Bets .Where(x => x.Result == teamKey) .ToList() .ForEach(s => s.UserBets.Add(userBetViewModel)); }
private static void SetDefaultValueForHomeTeam(TodaysGamesSpecification todaysGamesSpecification) { var playoffGameDetails = todaysGamesSpecification.PlayoffGameDetails.First(); todaysGamesSpecification.HomeTeam = new Team { Name = playoffGameDetails.HomeTeamDisplayName }; }
private static void SetGoalsFromResultBet(TodaysGamesSpecification todaysGamesSpecification, Bet resultBet) { if (resultBet == null) { return; } todaysGamesSpecification.HomeGoals = resultBet.HomeGoals; todaysGamesSpecification.AwayGoals = resultBet.AwayGoals; }
private static void SetValuesFromBetForPlayoffGame(TodaysGamesSpecification todaysGamesSpecification, Team team, string userNameForUserBet) { var teamKey = team.Name + " videre"; var userBetViewModel = new UserBetViewModel { UserName = userNameForUserBet }; AddOrUpdateTodaysBet(todaysGamesSpecification, teamKey, userBetViewModel); }
private static void AddNewTodaysBet(TodaysGamesSpecification todaysGamesSpecification, string teamKey, UserBetViewModel userBetViewModel) { var todaysBets = new TodaysBet { Result = teamKey, UserBets = new List <UserBetViewModel> { userBetViewModel } }; todaysGamesSpecification.Bets.Add(todaysBets); }
private static void AddOrUpdateTodaysBet(TodaysGamesSpecification todaysGamesSpecification, string teamKey, UserBetViewModel userBetViewModel) { if (todaysGamesSpecification.Bets.Any(x => x.Result == teamKey)) { AddUserBetToExistingResult(todaysGamesSpecification, teamKey, userBetViewModel); } else { AddNewTodaysBet(todaysGamesSpecification, teamKey, userBetViewModel); } }
private void SetTeamsForTodaysGameSpecification(Game todaysGame, TodaysGamesSpecification todaysGamesSpecification, UserBet resultUserBet, List <Team> teams) { if (IsGroupGame(todaysGamesSpecification)) { SetTeamValuesForGroupGames(todaysGame, todaysGamesSpecification, teams); } else { SetTeamValuesForPlayoffGames(todaysGamesSpecification, resultUserBet, teams); } }
private static List <TodaysBet> OrderByScoreOrNumberOfUsers(TodaysGamesSpecification todaysGamesSpecification) { if (todaysGamesSpecification.Bets.Any(x => x.UserBets.FirstOrDefault()?.Score != null)) { return(todaysGamesSpecification.Bets .OrderByDescending(x => x.UserBets.FirstOrDefault()?.Score) .ThenByDescending(x => x.UserBets.Count) .ToList()); } return(todaysGamesSpecification.Bets .OrderByDescending(x => x.UserBets.Count) .ToList()); }
private void SetTeamValuesForGroupGames(Game todaysGame, TodaysGamesSpecification todaysGamesSpecification, List <Team> teams) { if (todaysGame.HomeTeam != null) { todaysGamesSpecification.HomeTeam = teams.FirstOrDefault(x => x.Id == todaysGame.HomeTeam); } if (todaysGame.AwayTeam != null) { todaysGamesSpecification.AwayTeam = teams.FirstOrDefault(x => x.Id == todaysGame.AwayTeam); } }
private static void SetResultsIfAvailable(UserBet resultUserBet, TodaysGamesSpecification todaysGamesSpecification) { if ((GameType)todaysGamesSpecification.GameType == GameType.GroupGame) { var resultBet = resultUserBet?.Bets?.FirstOrDefault(x => x.GameId == todaysGamesSpecification.Id); SetGoalsFromResultBet(todaysGamesSpecification, resultBet); } else { var resultBet = resultUserBet?.PlayoffBets?.FirstOrDefault(x => x.GameId == todaysGamesSpecification.Id); SetGoalsFromResultBet(todaysGamesSpecification, resultBet); } }
private void SetValuesFromBetForGroupGame(Game todaysGame, TodaysGamesSpecification todaysGamesSpecification, UserBet resultUserBet, UserBet userBet, List <ScoreBasis> scoreBasis) { var userNameForUserBet = _userRepository.GetUserByUserId(userBet.UserId).UserName; var currentGamesBet = userBet.Bets?.FirstOrDefault(x => x.GameId == todaysGame.Id); var currentGamesResultBet = resultUserBet?.Bets?.FirstOrDefault(x => x.GameId == todaysGame.Id); if (currentGamesBet == null) { return; } var userBetViewModel = CreateUserBetViewModel(todaysGame, scoreBasis, currentGamesResultBet, currentGamesBet, userNameForUserBet); AddUserBetToListForGroup(todaysGamesSpecification, currentGamesBet, userBetViewModel); }
private void SetValuesForPlayoffGame(Game todaysGame, TodaysGamesSpecification todaysGamesSpecification, UserBet userBet) { var userNameForUserBet = _userRepository.GetUserByUserId(userBet.UserId).UserName; int nextRoundGameType; if ((GameType)todaysGame.GameType == GameType.SemiFinals) { nextRoundGameType = todaysGame.GameType + 2; } else { nextRoundGameType = todaysGame.GameType + 1; } var betsForNextRound = userBet.PlayoffBets.Where(x => x.GameType == (nextRoundGameType)).ToList(); if (!betsForNextRound.Any() || (GameType)todaysGame.GameType == GameType.BronzeFinals) { return; } foreach (var playoffBet in betsForNextRound) { if (todaysGamesSpecification.HomeTeam != null) { if (TeamMatchesUsersNextRoundBet(todaysGamesSpecification.HomeTeam.Id, playoffBet)) { SetValuesFromBetForPlayoffGame(todaysGamesSpecification, todaysGamesSpecification.HomeTeam, userNameForUserBet); } } if (todaysGamesSpecification.AwayTeam != null) { if (TeamMatchesUsersNextRoundBet(todaysGamesSpecification.AwayTeam.Id, playoffBet)) { SetValuesFromBetForPlayoffGame(todaysGamesSpecification, todaysGamesSpecification.AwayTeam, userNameForUserBet); } } } }
private void SetValuesFromUserBets(Game todaysGame, IEnumerable <UserBet> userBets, TodaysGamesSpecification todaysGamesSpecification, UserBet resultUserBet) { var scoreBasis = _scoreBasisRepository.GetScoreBasisesBySportsEventId(1); foreach (var userBet in userBets) { if (IsGroupGame(todaysGamesSpecification)) { SetValuesFromBetForGroupGame(todaysGame, todaysGamesSpecification, resultUserBet, userBet, scoreBasis); } if ((GameType)todaysGamesSpecification.GameType != GameType.GroupGame) { SetValuesForPlayoffGame(todaysGame, todaysGamesSpecification, userBet); } } }
private static bool IsGroupGame(TodaysGamesSpecification todaysGamesSpecification) { return((GameType)todaysGamesSpecification.GameType == GameType.GroupGame); }
private static void SetValuesDefaultValuesForTeams(TodaysGamesSpecification todaysGamesSpecification) { SetDefaultValueForHomeTeam(todaysGamesSpecification); SetDefaultValueForAwayTeam(todaysGamesSpecification); }