Пример #1
0
        private static void AddUserBetToListForGroup(TodaysGamesSpecification todaysGamesSpecification,
                                                     Bet currentGamesBet, UserBetViewModel userBetViewModel)
        {
            var resultAsString = currentGamesBet.HomeGoals + "-" + currentGamesBet.AwayGoals;

            AddOrUpdateTodaysBet(todaysGamesSpecification, resultAsString, userBetViewModel);
        }
Пример #2
0
        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);
                }
            }
        }
Пример #3
0
 private static void AddUserBetToExistingResult(TodaysGamesSpecification todaysGamesSpecification, string teamKey,
                                                UserBetViewModel userBetViewModel)
 {
     todaysGamesSpecification.Bets
     .Where(x => x.Result == teamKey)
     .ToList()
     .ForEach(s => s.UserBets.Add(userBetViewModel));
 }
Пример #4
0
        private static void SetDefaultValueForHomeTeam(TodaysGamesSpecification todaysGamesSpecification)
        {
            var playoffGameDetails = todaysGamesSpecification.PlayoffGameDetails.First();

            todaysGamesSpecification.HomeTeam = new Team {
                Name = playoffGameDetails.HomeTeamDisplayName
            };
        }
Пример #5
0
 private static void SetGoalsFromResultBet(TodaysGamesSpecification todaysGamesSpecification, Bet resultBet)
 {
     if (resultBet == null)
     {
         return;
     }
     todaysGamesSpecification.HomeGoals = resultBet.HomeGoals;
     todaysGamesSpecification.AwayGoals = resultBet.AwayGoals;
 }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
 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);
     }
 }
Пример #9
0
 private void SetTeamsForTodaysGameSpecification(Game todaysGame,
                                                 TodaysGamesSpecification todaysGamesSpecification, UserBet resultUserBet, List <Team> teams)
 {
     if (IsGroupGame(todaysGamesSpecification))
     {
         SetTeamValuesForGroupGames(todaysGame, todaysGamesSpecification, teams);
     }
     else
     {
         SetTeamValuesForPlayoffGames(todaysGamesSpecification, resultUserBet, teams);
     }
 }
Пример #10
0
 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());
 }
Пример #11
0
        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);
            }
        }
Пример #12
0
 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);
     }
 }
Пример #13
0
        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);
        }
Пример #14
0
        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);
                    }
                }
            }
        }
Пример #15
0
        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);
                }
            }
        }
Пример #16
0
 private static bool IsGroupGame(TodaysGamesSpecification todaysGamesSpecification)
 {
     return((GameType)todaysGamesSpecification.GameType == GameType.GroupGame);
 }
Пример #17
0
 private static void SetValuesDefaultValuesForTeams(TodaysGamesSpecification todaysGamesSpecification)
 {
     SetDefaultValueForHomeTeam(todaysGamesSpecification);
     SetDefaultValueForAwayTeam(todaysGamesSpecification);
 }