private Error SellStocks(StockEvent e) { Stock_M s = _mainModel.Stocks.Find((stock) => stock.Tag == e.Name); if (s != null) { BuyOrSell_M bos = _currentPortfolio.CurrentlyHeld().Find(b => b.StockName == s.Name); if (e.Amount > bos.Quantity) { return(new Error("Selling too many stocks")); } _currentPortfolio.SellStock(s, e.Amount); } Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name)); return(Error.None); }
private Error BuyStocks(StockEvent e) { Stock_M s = _mainModel.Stocks.Find((stock) => stock.Tag == e.Name); if (s != null) { if (_currentPortfolio.CurrentlyHeld().Exists(b => b.StockName == s.Name)) { return(new Error("Cannot buy stock you already own")); } try { _currentPortfolio.PurchaseStock(s, e.Amount); } catch (ArgumentException err) { return(new Error(err.Message)); } } Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name)); return(Error.None); }