public async Task <IndexResult> AddData([FromBody] string indexName) { var addData = new IndexResult(); if (string.IsNullOrEmpty(indexName)) { addData.Messages = new List <AlertViewModel> { new AlertViewModel("danger", "no indexName defined", "Please provide the index name"), }; return(addData); } try { PersonCityData.CreateTestData(); await _searchProviderIndex.AddDocumentsToIndex(PersonCityData.Data).ConfigureAwait(false); addData.Messages = new List <AlertViewModel> { new AlertViewModel("success", "Documented added", "The Azure Search documents were uploaded! The Document Count takes n seconds to update!"), }; var indexStatus = await _searchProviderIndex.GetIndexStatus().ConfigureAwait(false); addData.Status.IndexExists = indexStatus.Exists; addData.Status.DocumentCount = indexStatus.DocumentCount; return(addData); } catch (Exception ex) { addData.Messages = new List <AlertViewModel> { new AlertViewModel("danger", "Error adding documents", ex.Message), }; return(addData); } }
public async Task <ActionResult> OnPostAddDataAsync() { try { PersonCityData.CreateTestData(); await _searchProviderIndex.AddDocumentsToIndex(PersonCityData.Data).ConfigureAwait(false); Messages = new[] { new AlertViewModel("success", "Documented added", "The Azure Search documents were uploaded! The Document Count takes n seconds to update!"), }; var indexStatus = await _searchProviderIndex.GetIndexStatus().ConfigureAwait(false); IndexExists = indexStatus.Exists; DocumentCount = indexStatus.DocumentCount; return(Page()); } catch (Exception ex) { Messages = new[] { new AlertViewModel("danger", "Error adding documents", ex.Message), }; return(Page()); } }