/// <summary> /// Updates the price history for tickers in a watch list. /// </summary> private void UpdateTickersInWatchList() { // First, print a list of watch lists for the user to choose from. this.DisplayWatchLists(); // Prompt the user to select the watch list that will be updated with new data. Console.Write("Select ID of watch list to update. ([Blank] to cancel.) --> "); var input = Console.ReadLine(); if (string.IsNullOrWhiteSpace(input)) { // The user opted to cancel without entering an ID. Console.WriteLine(); return; } int id; if (!int.TryParse(input, out id)) { // Invalid Input -- non-numeric data!!! Console.WriteLine("Invalid input...no watch list was updated."); Console.WriteLine(); return; } using (var context = new StockScreenerEntities()) { var watchLists = context.Watchlists.ToList(); if (watchLists.Count(list => list.ID == id) <= 0) { // Invalid Input -- invalid Watch List ID!!! Console.WriteLine("Invalid input...no watch list was upated."); Console.WriteLine(); } else { // Valid Input -- Update the selected watch list. var dataUpdater = new DataUpdater(); dataUpdater.UpdateTickerHistories(watchLists.First(list => list.ID == id).Stocks); } } }
/// <summary> /// Updates the price history for all tickers in the database. /// </summary> private void UpdateAllTickers() { List<Stock> stocks; using (var context = new StockScreenerEntities()) { stocks = context.Stocks.ToList(); } var dataUpdater = new DataUpdater(); dataUpdater.UpdateTickerHistories(stocks); Console.ReadLine(); }