public async Task <bool> AddTransaction(Guid playerId, TransactionType type, decimal amount) { if (amount <= 0) { throw new InvalidAmountException(amount); } var player = await _playerRepository.GetPlayer(playerId); if (player == null) { throw new PlayerNotFoundException(); } if (player.Wallet == null) { throw new WalletNotFound(); } if (type == TransactionType.Stake && player.Wallet.Balance < amount) { return(false); } var transaction = new Transaction { Type = type, Amount = amount, PlayerId = playerId }; ProcessTransaction(transaction, player.Wallet); await _playerRepository.UpdatePlayer(player); await _playerRepository.AddTransaction(transaction); return(true); }