public async Task <IActionResult> RegionUpdate([FromBody] CmsPostWebHookApiModel model) { if (model == null) { return(BadRequest("delete model empty or null.")); } var postId = model.post_id; if (postId <= 0) { return(BadRequest($"post id null. model.post_id: {postId}")); } if (model.post.post_status == "trash") { var removeSuccessful = await _regionRepository.Delete(postId); if (!removeSuccessful) { _logger.LogError("Failed to delete region with id: {PostId} in elasticsearch.", postId); return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to delete region.")); } return(NoContent()); } var cmsRegion = await _cmsApiProxy.GetRegion(postId); var elasticRegion = await MapToElasticModel(cmsRegion); bool successful; var region = await _regionRepository.Get(postId); if (region == null) { successful = await _regionRepository.Insert(new List <RegionElasticModel> { elasticRegion }); if (!successful) { _logger.LogError("Failed to insert region with id:{PostId} in elasticsearch.", postId); return(BadRequest("Failed to insert region.")); } _logger.LogInformation("Inserted region with id {PostId} to elasticsearch successfully.", postId); return(Created(elasticRegion.Id.ToString(), elasticRegion)); } successful = await _regionRepository.Update(elasticRegion); if (!successful) { _logger.LogError("Failed to update region with id:{PostId} in elasticsearch.", postId); return(BadRequest("Failed to update region.")); } _logger.LogInformation("Updated region with id {PostId} to elasticsearch successfully.", postId); // TODO: FIX THIS!!!!!! // Update business cache! await SyncBusiness(); // Update pages cache! var apiPath = model.post.post_type; _cmsApiProxy.RemovePagesCache(apiPath); await _cmsApiProxy.GetPages(regionPageApiPath : apiPath); return(Ok()); }