public async Task <int> BulkImportAsync(ProviderVenueQualificationFileImportDto fileImportDto)
        {
            _logger.LogInformation($"Processing {nameof(ProviderVenueQualificationFileImportDto)}.");

            var readResultDto = _fileReader.ReadData(fileImportDto);

            if (readResultDto?.ProviderVenueQualifications == null || !readResultDto.ProviderVenueQualifications.Any())
            {
                _logger.LogInformation("No Data Imported.");
                return(0);
            }

            var results =
                (await _providerVenueQualificationService.UpdateAsync(readResultDto.ProviderVenueQualifications))
                .ToList();

            // Log errors in data updates
            foreach (var result in results.Where(result => result.HasErrors))
            {
                _logger.LogError(result.Message);
                await _functionLogRepository.CreateAsync(new FunctionLog
                {
                    ErrorMessage = result.Message,
                    FunctionName = nameof(ProviderVenueQualificationFileImportService),
                    RowNumber    = -1
                });
            }

            var updatedCount = results.Count(x => x.HasErrors == false);

            _logger.LogInformation($"{updatedCount} out of {readResultDto.ProviderVenueQualifications.Count} Providers data successfully updated.");

            return(updatedCount);
        }
Exemplo n.º 2
0
        public When_ProviderVenueQualificationFileImportService_Is_Called_To_Bulk_Import_Data()
        {
            var logger = Substitute.For <ILogger <IProviderVenueQualificationFileImportService> >();

            _fileReader = Substitute.For <IProviderVenueQualificationReader>();
            _providerVenueQualificationService = Substitute.For <IProviderVenueQualificationService>();
            _functionLogRepository             = Substitute.For <IRepository <FunctionLog> >();

            var fileImportDto       = new ValidProviderVenueQualificationFileImportDtoBuilder().Build();
            var readResultDto       = new ValidProviderVenueQualificationReadResultDtoBuilder().Build();
            var updateResultDtoList = new ValidProviderVenueQualificationUpdateResultsDtoBuilder().Build();

            _fileReader.ReadData(fileImportDto)
            .Returns(readResultDto);

            _providerVenueQualificationService.UpdateAsync(readResultDto.ProviderVenueQualifications)
            .Returns(updateResultDtoList);

            var service = new ProviderVenueQualificationFileImportService(logger, _fileReader,
                                                                          _providerVenueQualificationService, _functionLogRepository);

            _result = service.BulkImportAsync(fileImportDto).GetAwaiter().GetResult();
        }