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(); }
public EmbeddedOrderViewModel(IEventAggregator events, Stock stock) { this._events = events; events.Subscribe(this); StockOrder = new StockOrder {Stock = stock}; }
public void IncreaseOrder() { StockOrder = new StockOrder { Amount = ++StockOrder.Amount, Stock = StockOrder.Stock }; _events.Publish(new StockOrderPlacedEvent(StockOrder, true)); }
public void DecreaseOrder() { StockOrder = new StockOrder { Amount = --StockOrder.Amount, Stock = StockOrder.Stock }; _events.Publish(new StockOrderPlacedEvent(StockOrder, false)); }
public StockOrderPlacedEvent(StockOrder stockOrder, bool added) { this.StockOrder = stockOrder; this.Added = added; }
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)); }