public async Task <ActionResult> AddData([FromBody] NewYorkAddDtos newYorkAddDtos) { bool result = await _newYorkRepository.AddData(newYorkAddDtos); if (result) { return(NoContent()); } return(BadRequest("Failed to add data")); }
public async Task <bool> AddData(NewYorkAddDtos newYorkAddDtos) { ISearchResponse <NewYork> searchResponse = await Exists(newYorkAddDtos.id); if (searchResponse != null) { var updateResponse = await _client.UpdateAsync <NewYorkAddDtos>( DocumentPath <NewYorkAddDtos> .Id(searchResponse.Hits.FirstOrDefault().Id), descriptor => descriptor .RetryOnConflict(3) .Doc(newYorkAddDtos) .Refresh(Refresh.True) ); return(updateResponse.IsValid); } else { var addResponse = await _client.IndexDocumentAsync <NewYorkAddDtos>(newYorkAddDtos); return(addResponse.IsValid); } }