public async Task <string> GetTest() { var apiStocks = await _fmpCloudClient.GetAllStocks(); foreach (var apiStock in apiStocks) { var existing = _context.Stocks.Where(stock => stock.Symbol == apiStock.Symbol); if (existing.Count() > 0) { var dayPrices = await _fmpCloudClient.GetDailyPrices(apiStock.Symbol); foreach (var stock in existing) { var yearlyDayPrices = dayPrices.DailyPrices.Where(dayPrice => DateTime.ParseExact(dayPrice.Date ?? "0001-01-01", "yyyy-MM-dd", null).Year == stock.Year) .OrderBy(priceComponent => DateTime.ParseExact(priceComponent.Date ?? "0001-01-01", "yyyy-MM-dd", null)); stock.YearlyStartSharePrice = yearlyDayPrices.Count() > 0 ? yearlyDayPrices.First().Price : 0m; stock.YearlyEndSharePrice = yearlyDayPrices.Count() > 0 ? yearlyDayPrices.Last().Price : 0m; } _context.SaveChanges(); } } return($"Done with {apiStocks.Count()} stocks"); }