Beispiel #1
0
        public int AddFunds(int value)
        {
            var transaction = new WalletTransactionDomainModel();

            transaction.AddDeposit(value);

            return(walletTransactionRepository.Create(transaction));
        }
Beispiel #2
0
        public void Bet_transaction_should_not_be_positive()
        {
            var transaction = new WalletTransactionDomainModel()
            {
                TransactionType  = Common.Core.Enums.TransactionType.Bet,
                TransactionValue = 20
            };

            Assert.Throws <Exception>(() => transaction.ErrorCheck());
        }
Beispiel #3
0
        public IEnumerable <int> CreateTransactionsForBets(ICollection <Tuple <BetDomainModel, float> > betTransactions)
        {
            var transactions = new List <WalletTransactionDomainModel>();

            foreach (var betTransaction in betTransactions)
            {
                var transaction = new WalletTransactionDomainModel();
                transaction.AddBetWithValue(betTransaction.Item1, betTransaction.Item2);
                transactions.Add(transaction);
            }

            return(walletTransactionRepository.CreateMany(transactions));
        }
Beispiel #4
0
        public void PlaceBet(BetDto dto)
        {
            var offer = gameQuery.AsGameOfferView();
            var bestOffersCoefficients = offer.BestOffers.SelectMany(e => e.Coefficients).Where(e => dto.CoefficientIds.Contains(e.Id));
            var allOffersCoefficients  = offer.OtherOffers.SelectMany(e => e.Coefficients).Concat(bestOffersCoefficients).Where(e => dto.CoefficientIds.Contains(e.Id));

            if (allOffersCoefficients.Count() == 0)
            {
                throw new Exception("At least one current offer coefficient needs to be selected.");
            }

            if (allOffersCoefficients.GroupBy(x => x.GameId).Any(g => g.Count() > 1))
            {
                throw new Exception("There can only be one coefficient selected per offered game in a bet.");
            }

            if (bestOffersCoefficients.Count() > 2)
            {
                throw new Exception("There can only be one special offer coefficient selected per bet.");
            }

            var totalFunds = walletTransactionQuery.AsTotalFundsView(includeTransactions: false);

            if (MIN_BET_VALUE >= dto.BetValue || dto.BetValue >= totalFunds.TotalFunds)
            {
                throw new Exception("You can only bet if you have sufficient funds (minimum: " + MIN_BET_VALUE + ")");
            }

            var bet = new BetDomainModel {
                Coefficients = betRepository.GetCoefficientsForBet(dto.CoefficientIds)
            };

            bet.Id = betRepository.Create(bet);

            var transaction = new WalletTransactionDomainModel();

            transaction.AddBetWithValue(bet, dto.BetValue);

            walletTransactionService.CreateTransactionsForBets(new List <Tuple <BetDomainModel, float> >()
            {
                new Tuple <BetDomainModel, float>(bet, dto.BetValue)
            });
        }