Example #1
0
        internal void SellStock(string ticker, int quantity, double amount)
        {
            var newStock = Stock.Create(this, ticker, quantity, amount);
            var stock    = this.Stocks?.FirstOrDefault(s => s.Ticker == newStock.Ticker);

            if (stock == null)
            {
                throw new StockException("Ticker not found");
            }
            if (this.Transactions == null)
            {
                this.Transactions = new List <Transaction>();
            }

            Raise(StockSoldDomainEvent.Create(this, newStock));
        }
Example #2
0
        internal static void When(StockSoldDomainEvent @event)
        {
            var newStock = (Stock)@event.Stock;
            var stock    = @event.Wallet.Stocks?.FirstOrDefault(s => s.Ticker == newStock.Ticker);

            if (stock.Quantity == newStock.Quantity)
            {
                @event.Wallet.Stocks.Remove(stock);
            }
            else
            {
                stock.SellStock(newStock.Quantity);
            }

            @event.Wallet.Raise(TransactionCreatedDomainEvent.Create(@event.Wallet, newStock, false));
        }