public void GetCustomerConsentDataReport() { try { var accounts = _corporateAccountRepository.GetAllCorporateAccountToSendConsentData(); if (accounts.IsNullOrEmpty()) { _logger.Info("No Account marked to Send Consent Data to Matrix"); return; } foreach (var corporateAccount in accounts) { try { _logger.Info("starting for Account " + corporateAccount.Tag); var serviceReportSettings = string.Format(_settings.CustomerConsentDataReportSettingPath, corporateAccount.Tag); var customSettings = _customSettingManager.Deserialize(serviceReportSettings); var fromDate = customSettings.LastTransactionDate; customSettings.LastTransactionDate = DateTime.Now; _customSettingManager.SerializeandSave(serviceReportSettings, customSettings); var filter = new CustomerConsentDataListModelFilter { AccountId = corporateAccount.Id, Tag = corporateAccount.Tag, FromDate = fromDate }; var pageNumber = 1; var destinationFoler = Path.Combine(_settings.CustomerConsentDataFilePath, corporateAccount.Tag); DirectoryOperationsHelper.CreateDirectoryIfNotExist(destinationFoler); var fileName = "CustomerConsentDataReport_" + DateTime.Today.ToString("yyyyMMdd") + ".txt"; var destinationFile = Path.Combine(destinationFoler, fileName); DirectoryOperationsHelper.DeleteFileIfExist(destinationFile); WriteHeader(destinationFile); var index = 1; while (true) { int totalRecords = 0; var customers = _customerRepository.GetCustomerConsentDataReport(filter, pageNumber, PageSize, out totalRecords); if (customers != null) { foreach (var customer in customers) { _logger.Info("CustomerId:" + customer.CustomerId); _logger.Info(index + " out of " + totalRecords); index++; var model = new CustomerConsentDataViewModel(); model.AcesId = customer.AcesId; if (!string.IsNullOrEmpty(customer.HomePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneHomeConsentUpdateDate.HasValue && customer.PhoneHomeConsentUpdateDate.Value >= fromDate))) { model.TelephoneNumber = customer.HomePhoneNumber.FormatPhoneNumber; model.ConsentType = ((PatientConsent)customer.PhoneHomeConsentId).GetDescription(); model.ConsentDateTime = customer.PhoneHomeConsentUpdateDate; WriteData(model, destinationFile); } if (!string.IsNullOrEmpty(customer.MobilePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneCellConsentUpdateDate.HasValue && customer.PhoneCellConsentUpdateDate.Value >= fromDate))) { model.TelephoneNumber = customer.MobilePhoneNumber.FormatPhoneNumber; model.ConsentType = ((PatientConsent)customer.PhoneCellConsentId).GetDescription(); model.ConsentDateTime = customer.PhoneCellConsentUpdateDate; WriteData(model, destinationFile); } if (!string.IsNullOrEmpty(customer.OfficePhoneNumber.ToString()) && (fromDate == null || (customer.PhoneOfficeConsentUpdateDate.HasValue && customer.PhoneOfficeConsentUpdateDate.Value >= fromDate))) { model.TelephoneNumber = customer.OfficePhoneNumber.FormatPhoneNumber; model.ConsentType = ((PatientConsent)customer.PhoneOfficeConsentId).GetDescription(); model.ConsentDateTime = customer.PhoneOfficeConsentUpdateDate; WriteData(model, destinationFile); } } } if ((pageNumber * PageSize) >= totalRecords) { break; } pageNumber++; } if (_settings.CustomerConsentDataReportSendToSftp) { if (ExportReportOnMatrixSftp(fileName, destinationFile)) { _logger.Info("File posted on client SFTP"); } else { _logger.Info("File didn't posted,some error occurred."); } } _logger.Info("completed for Account " + corporateAccount.Tag); } catch (Exception ex) { _logger.Error("some error occurred while creating customer consent data report for Account " + corporateAccount.Tag); _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } } } catch (Exception ex) { _logger.Error("Message: " + ex.Message); _logger.Error("Stack Trace: " + ex.StackTrace); } }