Exemplo n.º 1
0
        public void Execute()
        {
            this.logger.RunWithExceptionLogging(() =>
            {
                this.tradeTable.Draw(sharesService.GetAllShares());
            });

            this.logger.WriteMessage("Got all shares from shares base.");
        }
        public void SellOrBuyShares(Transaction transaction)
        {
            ClientPortfolio portfolios = new ClientPortfolio()
            {
                ClientID       = transaction.SellerID,
                ShareID        = transaction.ShareID,
                AmountOfShares = -transaction.AmountOfShares
            };

            if (transaction.SellerID == transaction.BuyerID)
            {
                throw new ArgumentException("Seller and buyer are the same person.");
            }

            portfoliosService.ChangeAmountOfShares(portfolios);
            portfolios.AmountOfShares *= -1;
            portfolios.ClientID        = transaction.BuyerID;
            portfoliosService.ChangeAmountOfShares(portfolios);

            decimal sharePrice = sharesService.GetAllShares().Where(x => x.ShareID == transaction.ShareID).Select(x => x.Price).FirstOrDefault();

            clientService.ChangeBalance(transaction.SellerID, sharePrice * transaction.AmountOfShares);
            clientService.ChangeBalance(transaction.BuyerID, -(sharePrice * transaction.AmountOfShares));
        }