private Error NewPortfolio(PortfolioEvent e) { try { _mainModel.Account.CreatePortfolio(e.PortfolioName, _mainModel.VerifyStock); _currentPortfolio = _mainModel.Account.GetPortfolioByName(e.PortfolioName); Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name)); } catch (ArgumentException err) { return(new Error(err.Message)); } return(Error.None); }
private Error DeletePortfolio(PortfolioEvent e) { try { _mainModel.Account.DeletePortfolio(e.PortfolioName, _mainModel.Stocks); } catch (ArgumentException err) { return(new Error(err.Message)); } _currentPortfolio = null; Broadcast(new PortfolioEvent("portfolio", "")); return(Error.None); }
/// <summary> /// Deletes a portfolio from the account /// </summary> /// <param name="name">Name of portfolio to be deleted</param> public void DeletePortfolio(string name, List <Stock_M> stocks) { Portfolio_M selectedPortfolio = GetPortfolioByName(name); foreach (BuyOrSell_M BOS in selectedPortfolio.CurrentlyHeld()) { Stock_M stock = stocks.Find(s => BOS.StockName == s.Name); selectedPortfolio.SellStock(stock, BOS.Quantity); } _transactions.AddRange(selectedPortfolio.TransactionList); if (_portfolios.RemoveAll((p) => p.Name == name) == 0) { throw new ArgumentException("No portfolio exists with that name."); } }
private Error ViewPortfolio(PortfolioEvent e) { if (_mainModel.Account.Portfolios.Exists((p) => p.Name == e.PortfolioName)) { _currentPortfolio = _mainModel.Account.GetPortfolioByName(e.PortfolioName); } else { return(new Error("No portfolio exists with that name.")); } if (_currentPortfolio != null) { Broadcast(new PortfolioEvent("portfolio", _currentPortfolio.Name)); } else { Broadcast(new PortfolioEvent("portfolio", "")); } return(Error.None); }