private async Task <TResponse> DoBetCommandTransactions <TRequest, TResponse>(TRequest request, Func <Guid, BetCommandTransactionRequest, Task <BetCommandResponseTransaction> > betCommandPerTransaction) where TResponse : BetCommandResponse, new() where TRequest : BetCommandRequest { using (var scope = _transactionScope.GetTransactionScopeAsync()) { var playerId = GetPlayerIdFromToken(request); var resultTransactions = new List <BetCommandResponseTransaction>(); foreach (var betCommandTransactionRequest in request.Transactions) { var betCommandResult = await betCommandPerTransaction.Invoke(playerId, betCommandTransactionRequest); resultTransactions.Add(betCommandResult); } var balance = await _gameQueries.GetPlayableBalanceAsync(playerId); scope.Complete(); return(new TResponse { Balance = balance.Balance, CurrencyCode = balance.CurrencyCode, Transactions = resultTransactions }); } }