Beispiel #1
0
        public void ResolvePendingBets()
        {
            var bets = betRepository.GetUnresolvedBets();

            var betStatuses = betQuery.WhereBetIds(bets.Select(e => e.Id)).Project().ToArray();

            var betTransactions = new List <Tuple <BetDomainModel, float> >();

            foreach (var bet in bets)
            {
                var betStatus = betStatuses.FirstOrDefault(e => e.Id == bet.Id);
                if (betStatus != null && betStatus.IsResolvable && !betStatus.IsResolved)
                {
                    bet.Resolve();

                    if (betStatus.Games.All(e => e.IsGuessed))
                    {
                        betTransactions.Add(new Tuple <BetDomainModel, float>(bet, CalculateProfit(betStatus)));
                    }
                }
            }

            betRepository.UpdateMany(bets);

            walletTransactionService.CreateTransactionsForBets(betTransactions);
        }