コード例 #1
0
        public IEnumerable <Statement> DownloadLatestStatements(BankParams[] bankParamsList)
        {
            try
            {
                var potentiallyNewStatements = new List <Statement>();
                var startDate = DateTime.Now - TimeSpan.FromDays(80);
                var endDate   = DateTime.Now;
                bankParamsList.ToList().ForEach(bp => potentiallyNewStatements.AddRange(_finTsExecutor.Download(startDate, endDate, bp)));

                var existingStatements = _statementRepository.GetStatements();
                var newStatements      = potentiallyNewStatements.Where(pns => !existingStatements.Contains(pns));

                if (newStatements.Any())
                {
                    _statementRepository.StoreStatements(newStatements);
                }

                var countNewStatements = newStatements.Count();
                _logger?.LogInformation("Stored {countNewStatements} new statements in the database.", countNewStatements);
                return(newStatements);
            }
            catch (Exception e)
            {
                _logger?.LogError(e, e.Message);
                return(new List <Statement>());
            }
        }