public async Task Run(string learnAimRef, ILogger log) { if (string.IsNullOrWhiteSpace(learnAimRef)) { log.LogError($"{nameof(PurgeLarsFromDatabaseAndSearch)} failed with invalid {nameof(learnAimRef)} {{{nameof(learnAimRef)}}}.", learnAimRef); } log.LogInformation($"{nameof(PurgeLarsFromDatabaseAndSearch)} invoked for {nameof(learnAimRef)} {{{nameof(learnAimRef)}}}.", learnAimRef); var deletedResult = await _sqlQueryDispatcher.ExecuteQuery(new DeleteLarsLearningDelivery(learnAimRef)); deletedResult.Switch( _ => log.LogInformation($"{nameof(PurgeLarsFromDatabaseAndSearch)} successfully deleted {nameof(learnAimRef)}: {{{nameof(learnAimRef)}}} from database.", learnAimRef), _ => log.LogWarning($"{nameof(PurgeLarsFromDatabaseAndSearch)} failed to find {nameof(learnAimRef)} {{{nameof(learnAimRef)}}} in database.", learnAimRef)); try { await _searchClient.GetDocumentAsync <dynamic>(learnAimRef); await _searchClient.DeleteDocumentsAsync("LearnAimRef", new[] { learnAimRef }, new IndexDocumentsOptions { ThrowOnAnyError = true }); log.LogInformation($"{nameof(PurgeLarsFromDatabaseAndSearch)} successfully deleted {nameof(learnAimRef)} {{{nameof(learnAimRef)}}} from search index.", learnAimRef); } catch (RequestFailedException ex) when(ex.Status == StatusCodes.Status404NotFound) { log.LogWarning($"{nameof(PurgeLarsFromDatabaseAndSearch)} failed to find {nameof(learnAimRef)} {{{nameof(learnAimRef)}}} in search.", learnAimRef); } }
public Task DeleteAccommodationIndexAsync(int accommodationId) { return(client.DeleteDocumentsAsync("Id", new[] { accommodationId.ToString() })); }