예제 #1
0
        public void PlaceStockOrder(StockOrder stockOrder)
        {
            var stock = AvailableStocks.Find(stockOrder.Stock.StockId);
            if (stock == null) return;
            if (stockOrder.Amount == 0) return;

            for (var i = 0; i < stockOrder.Amount; i++)
            {
                // Increase current price of ordered stocks.
                var toIncrease = (stock.MaximumPrice - stock.CurrentPrice) * UpPercentage;
                stock.CurrentPrice += toIncrease;

                // Decrease the prices of the other stocks.
                foreach (var availableStock in AvailableStocks)
                {
                    if (availableStock == stock) continue;

                    var toDecrease = (availableStock.CurrentPrice - availableStock.MinimumPrice) * DownPercentage;
                    availableStock.CurrentPrice -= toDecrease;
                }
            }

            // Adjust pricehistory of all stocks.
            foreach (var availableStock in AvailableStocks)
            {
                availableStock.PriceHistory.Add(new StockPriceHistory
                                                    {
                                                        DateOfPlacement = DateTime.Now,
                                                        Price = availableStock.CurrentPrice
                                                    });
            }

            this.SaveChanges();
        }
예제 #2
0
        public EmbeddedOrderViewModel(IEventAggregator events, Stock stock)
        {
            this._events = events;
            events.Subscribe(this);

            StockOrder = new StockOrder {Stock = stock};
        }
예제 #3
0
        public void IncreaseOrder()
        {
            StockOrder = new StockOrder
                             {
                                 Amount = ++StockOrder.Amount,
                                 Stock = StockOrder.Stock
                             };

            _events.Publish(new StockOrderPlacedEvent(StockOrder, true));
        }
예제 #4
0
        public void DecreaseOrder()
        {
            StockOrder = new StockOrder
                             {
                                 Amount = --StockOrder.Amount,
                                 Stock = StockOrder.Stock
                             };

            _events.Publish(new StockOrderPlacedEvent(StockOrder, false));
        }
예제 #5
0
 public StockOrderPlacedEvent(StockOrder stockOrder, bool added)
 {
     this.StockOrder = stockOrder;
     this.Added = added;
 }
예제 #6
0
        public void UpdateOrder(TextBox textbox)
        {
            var value = textbox.Text;
            int amount;
            int.TryParse(value, out amount);

            StockOrder = new StockOrder
                {
                    Amount = amount,
                    Stock = StockOrder.Stock
                };

            _events.Publish(new StockOrderPlacedEvent(StockOrder, true));
        }