public async Task <IActionResult> SyncTags() { var languages = await _cmsApiProxy.GetLanguages(); if (languages == null || !languages.Any()) { return(BadRequest("No languages found")); } var successful = await _tagRepository.DeleteIndex(); if (!successful) { _logger.LogError("Failed to delete tags index from elasticsearch."); return(BadRequest("Tags index failed to be removed.")); } foreach (var l in languages) { var tags = await _cmsApiProxy.GetTags(l.Code); if (tags == null || !tags.Any()) { continue; } var elasticTags = (await Task.WhenAll(tags.Select(MapToElasticModel))).ToList(); successful = await _tagRepository.Insert(elasticTags); if (!successful) { _logger.LogError("Failed to insert {Count} tags to elasticsearch.", elasticTags.Count); } } return(Ok()); }