Exemplo n.º 1
0
        public WalletEntity Buy(string userId, string stock, decimal price, int quantity)
        {
            var isPurchase = true;

            decimal totalPrice = price * quantity;

            var wallet = _walletQueryService.GetWallet(userId);

            if (wallet.Cash < totalPrice)
            {
                throw new InsufficientAvailableFundsException("There are insufficient funds to complete this transaction.");
            }

            _walletQueryService.Update(wallet.WalletId, totalPrice, isPurchase);

            _transactionQueryService.AddTransaction(userId, stock, price, quantity);

            return(wallet);
        }