Exemple #1
0
        internal void BuyStock(string ticker, int quantity, double amount)
        {
            var newStock = Stock.Create(this, ticker, quantity, amount);

            if (this.Stocks == null)
            {
                this.Stocks = new List <Stock>();
            }
            if (this.Transactions == null)
            {
                this.Transactions = new List <Transaction>();
            }

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

            if (stock == null)
            {
                stock = newStock;
                @event.Wallet.Stocks.Add(stock);
            }
            else
            {
                stock.AddStock(newStock.Quantity, newStock.Amount);
            }

            @event.Wallet.Raise(TransactionCreatedDomainEvent.Create(@event.Wallet, newStock, true));
        }
        internal void BuyStock(string ticker, int quantity, double amount)
        {
            var newStock = Stock.Create(this, ticker, quantity, amount);

            if (this.Stocks == null)
            {
                this.Stocks = new List <Stock>();
            }
            if (this.Transactions == null)
            {
                this.Transactions = new List <Transaction>();
            }
            if (newStock.Quantity < 1)
            {
                throw new StockException("Quantity informed is invalid");
            }
            if (newStock.Amount < 0)
            {
                throw new StockException("Invalid amount");
            }
            Raise(StockBougthDomainEvent.Create(this, newStock));
        }