Пример #1
0
        public IEnumerable <BetViewModel> GetGameBets(int id)
        {
            var game = gamesRepository.GetGame(id);

            if (game == null)
            {
                throw new ObjectNotFoundException(string.Format("Game with id '{0}' not found", id));
            }

            if (game.IsOpen(dateTimeProvider.UTCNow))
            {
                throw new ArgumentException(String.Format("Game '{0}' is stil open for betting", id));
            }

            return(betsRepository.GetGameBets(id).Select(item => new BetViewModel(item, dateTimeProvider.UTCNow)).OrderByDescending(bet => bet.Points));
        }
Пример #2
0
        public void ValidateNewBet(Bet bet)
        {
            var game = gamesRepository.GetGame(bet.GameId);

            if (game == null)
            {
                AddLog(ActionType.ERROR, string.Format("Game {0} dosen't exist", bet.Game.GameId));
                throw new ArgumentException(string.Format("Game {0} dosen't exist", bet.Game.GameId));
            }
            if (!game.IsOpen(dateTimeProvider.UTCNow))
            {
                AddLog(ActionType.ERROR, string.Format("Game {0} is closed for betting", game.GameId));
                throw new ArgumentException(string.Format("Game {0} is closed for betting", game.GameId));
            }
            if (String.IsNullOrEmpty(bet.UserId))
            {
                AddLog(ActionType.ERROR, "New bet must have an owner");
                throw new ArgumentException("New bet must have an owner");
            }
            if (betsRepository.GetGameBets(game.GameId).Any(b => b.UserId == bet.UserId))
            {
                AddLog(ActionType.ERROR, string.Format("You already have an existing bet on game {0}", game.GameId));
                throw new ArgumentException(string.Format("You already have an existing bet on game {0}", game.GameId));
            }
        }
Пример #3
0
        public void ResolveBets(Game game)
        {
            if (!game.IsBetResolved(dateTimeProvider.UTCNow))
            {
                throw new ArgumentException(string.Format("Game {0} is not resolved yet", game.GameId));
            }

            var bets = betsRepository.GetGameBets(game.GameId);

            foreach (Bet bet in bets)
            {
                var points = 0;
                if (bet.Mark() == game.Mark(dateTimeProvider.UTCNow))
                {
                    points         += 3;
                    bet.GameMarkWin = true;
                }
                else
                {
                    bet.GameMarkWin = false;
                }
                if ((bet.HomeScore == game.HomeScore) && (bet.AwayScore == game.AwayScore))
                {
                    points       += 2;
                    bet.ResultWin = true;
                }
                else
                {
                    bet.ResultWin = false;
                }
                if (game.CardsMark == bet.CardsMark)
                {
                    points      += 1;
                    bet.CardsWin = true;
                }
                else
                {
                    bet.CardsWin = false;
                }
                if (game.CornersMark == bet.CornersMark)
                {
                    points        += 1;
                    bet.CornersWin = true;
                }
                else
                {
                    bet.CornersWin = false;
                }
                bet.Points = points;
                betsRepository.UpdateBet(bet);
                Trace.TraceInformation("{0} of {1} got {2} points", bet, game, points);
                AddLog(ActionType.UPDATE, String.Format("Resolved bet {0} with points {1}", bet, points));
            }
            if (bets.Count() > 0)
            {
                betsRepository.Save();
            }
        }
Пример #4
0
        public void ResolveBets(Game game)
        {
            if (!game.IsBetResolved(dateTimeProvider.UTCNow))
            {
                throw new ArgumentException(string.Format("Game {0} is not resolved yet", game.GameId));
            }

            var bets = betsRepository.GetGameBets(game.GameId);

            foreach (Bet bet in bets)
            {
                bet.CornersWin = false;
                bet.CardsWin   = false;
                bet.ResultWin  = (bet.HomeScore == game.HomeScore) && (bet.AwayScore == game.AwayScore);
                var points = 0.0m;
                if (bet.Mark() == game.Mark(dateTimeProvider.UTCNow))
                {
                    if (bet.HomeScore > bet.AwayScore)
                    {
                        points += game.HomeRatio;
                    }
                    if (bet.HomeScore == bet.AwayScore)
                    {
                        points += game.TieRatio;
                    }
                    if (bet.HomeScore < bet.AwayScore)
                    {
                        points += game.AwayRatio;
                    }
                    points *= game.RatioWeight;
                    if (bet.ResultWin)
                    {
                        var totalGoals = game.AwayScore + game.HomeScore;
                        if (totalGoals < 2)
                        {
                            points *= 1.1m;
                        }
                        else if (totalGoals < 4)
                        {
                            points *= 1.2m;
                        }
                        else
                        {
                            points *= 1.3m;
                        }
                    }
                    bet.GameMarkWin = true;
                }
                else
                {
                    bet.GameMarkWin = false;
                }

                bet.Points = points;
                betsRepository.UpdateBet(bet);
                Trace.TraceInformation("{0} of {1} got {2} points", bet, game, points);
                AddLog(ActionType.UPDATE, String.Format("Resolved bet {0} with points {1}", bet, points));
            }
            if (bets.Count() > 0)
            {
                betsRepository.Save();
            }
        }