public async Task <IActionResult> SyncRegions() { var regions = await _cmsApiProxy.GetRegions(allLanguages : true); if (regions == null || !regions.Any()) { return(BadRequest("No regions to sync!")); } var successful = await _regionRepository.DeleteIndex(); if (!successful) { _logger.LogError("Failed to delete regions index from elasticsearch."); return(BadRequest("Regions index failed to be removed.")); } var elasticRegions = (await Task.WhenAll(regions.Select(MapToElasticModel))).ToList(); successful = await _regionRepository.Insert(elasticRegions); if (!successful) { _logger.LogError("Failed to insert {Count} regions to elasticsearch.", elasticRegions.Count); } return(Ok()); }