public async Task LoadDataFromStaging(DateTime timeStarted) { try { var routesToImport = await _routeImportRepository.GetAll(); var standardsToInsert = (await _standardImportRepository.GetAll()).ToList(); if (!standardsToInsert.Any()) { await AuditImport(timeStarted, 0); _logger.LogWarning("Standards import - No standards loaded. No standards retrieved from API"); return; } _standardRepository.DeleteAll(); _routeRepository.DeleteAll(); _logger.LogInformation($"Standards import - Adding {standardsToInsert.Count} to Standards table."); await _routeRepository.InsertMany(routesToImport.Select(c => (Route)c).ToList()); var standards = standardsToInsert.Select(c => (Standard)c).ToList(); await _standardRepository.InsertMany(standards); await AuditImport(timeStarted, standards.Count); _logger.LogInformation("Standards import - complete"); } catch (Exception e) { _logger.LogError("Standards import - an error occurred when trying to load data from staging.", e); throw; } }