private async Task <Ticket> CreateTicket(CommitTicketRequest request) { var pairsToBetIds = request.BetingPairs.Select(p => p.BetedPairId); var betablePairs = await _dataProvider.BetablePairs(pairsToBetIds); if (request.BetingPairs.Count != betablePairs.Count) { var betablePairsIds = betablePairs.Select(p => p.Id); var difference = pairsToBetIds.Except(betablePairsIds); throw new BetablePairsNotFound(difference); } var betedPairs = CreateBetedPairs(request, betablePairs).ToArray(); var ticket = new Ticket { BetedPairs = betedPairs, Stake = request.Stake, UserId = _currentUser.Id() }; CalculateQuota(ticket); _unitOfWork.Add(ticket); _unitOfWork.AddRange(ticket.BetedPairs); await _unitOfWork.SaveChanges(); return(ticket); }
public async Task SubtractMoney(decimal moneyAmmount, WalletTransaction.WalletTransactionType type) { var userId = _userAccessor.Id(); var wallet = await _dataProvider.UsersWallet(userId); if (wallet == null) { throw new ModelNotFound(typeof(UserWallet)); } var transaction = new WalletTransaction { WalletId = wallet.Id, MoneyInvolved = -moneyAmmount, Type = type }; await CommitTransaction(wallet, transaction); }