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) }); }
public ActionResult <TotalFundsView> GetTotalFunds(bool includeTransactions = true) { return(walletTransactionQuery.AsTotalFundsView(includeTransactions)); }