Example #1
0
        public async Task PerformUpdateTillToday()
        {
            var latestDateInDb = await _stockQuoteRepository.GetLatestSessionInDbDateAsync();

            var currentDate  = latestDateInDb.AddDays(1);
            var endDate      = DateTime.Today;
            var datesToCheck = new List <DateTime>();

            while (currentDate.Date <= endDate.Date)
            {
                if (currentDate.DayOfWeek != DayOfWeek.Saturday && currentDate.DayOfWeek != DayOfWeek.Sunday)
                {
                    datesToCheck.Add(currentDate.Date);
                }
                currentDate = currentDate.AddDays(1);
            }

            foreach (var date in datesToCheck)
            {
                await PerformDayUpdate(date);

                using var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
                _stockQuoteRepository.SaveChanges();
                scope.Complete();
                _logger.LogInfo($"Database updated to {date}");
            }
        }
        public int SaveChanges()
        {
            _stockQuoteRepository.SaveChanges();
            RebuildCache();

            return(_cache.Count);
        }