Exemple #1
0
        public static List <PlayerBetSummary> GetPlayerStandingsForSeason(int seasonID)
        {
            var season    = SeasonService.GetSeason(seasonID);
            var summaries = new List <PlayerBetSummary>();

            if (season == null)
            {
                return(summaries);
            }
            var seasonBets   = BetService.GetAllBetsForSeason(seasonID);
            var playerGroups = seasonBets.GroupBy(x => x.PlayerName);

            foreach (var group in playerGroups)
            {
                var summary       = new PlayerBetSummary();
                var wins          = group.Where(x => x.Result == Result.Win);
                var notWins       = group.Where(x => x.Result != Result.Win);
                var currentLoss   = notWins.Sum(x => x.Stake);
                var currentProfit = wins.Sum(x => (x.Stake * x.Odds) - x.Stake);
                summary.PlayerName = group.Key;
                summary.TotalBets  = group.Count();
                summary.BetsWon    = wins.Count();
                summary.CashResult = GetCurrentCash(season.StartingCash, season.MinimumCash, currentProfit, currentLoss);
                summaries.Add(summary);
            }
            return(summaries);
        }
        public static void CheckForZeroOutRefunds(int eventID)
        {
            var fullEvent = new Event();

            using (var session = RavenDocStore.Store.OpenSession())
            {
                fullEvent = session.Load <Event>(eventID);
            }
            if (fullEvent == null)
            {
                throw new Exception("event not found for id: " + eventID);
            }
            // only zero-out if all the bets on this event have been resolved
            if (fullEvent.BetLines.Any(x => x.Result == Result.TBD))
            {
                return;
            }

            var playerBets = BetService.GetBetsForEvent(eventID).GroupBy(x => x.PlayerName);

            foreach (var player in playerBets)
            {
                var stats = SeasonService.GetCurrentPlayerStats(fullEvent.SeasonID, player.Key);
                if (stats.CashResult < 0)
                {
                    var amount = 0 - stats.CashResult;
                    BetService.IssueRefund(eventID, player.Key, amount);
                }
            }
        }
Exemple #3
0
        public static PlayerBetSummary GetCurrentPlayerStats(int seasonID, string playerName)
        {
            var summary = new PlayerBetSummary();
            var season  = SeasonService.GetSeason(seasonID);
            var myBets  = BetService.GetAllBetsForSeason(seasonID)
                          .Where(x => x.PlayerName == playerName);
            var wins          = myBets.Where(x => x.Result == Result.Win);
            var notWins       = myBets.Where(x => x.Result != Result.Win);
            var currentLoss   = notWins.Sum(x => x.Stake);
            var currentProfit = wins.Sum(x => (x.Stake * x.Odds) - x.Stake);

            summary.PlayerName = playerName;
            summary.TotalBets  = myBets.Count();
            summary.BetsWon    = wins.Count();
            summary.CashResult = GetCurrentCash(season.StartingCash, season.MinimumCash, currentProfit, currentLoss);
            return(summary);
        }
Exemple #4
0
        public static bool PlayerHasEnoughMoney(int seasonID, String playerName, decimal stake)
        {
            var currentStandings = SeasonService.GetPlayerStandingsForSeason(seasonID);
            var playerSummary    = currentStandings.FirstOrDefault(x => x.PlayerName == playerName);
            var season           = GetSeason(seasonID);
            var total            = season.StartingCash; // default total is season starting amount

            if (playerSummary != null)
            {
                total = playerSummary.CashResult;
            }                                                                // if there are bets, calculate how much player has left
            if (total - stake > (0 - season.MinimumCash))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static void PlaceBets(List <Bet> bets)
        {
            var totalStake = bets.Sum(x => x.Stake);

            // error if total is more than person currently has
            if (SeasonService.PlayerHasEnoughMoney(bets[0].SeasonID, bets[0].PlayerName, totalStake))
            {
                using (var session = RavenDocStore.Store.OpenSession())
                {
                    foreach (var bet in bets)
                    {
                        session.Store(bet);
                    }
                    session.SaveChanges();
                }
            }
            else
            {
                throw new Exception("You do not have enough cash");
            }
        }