/// <summary> /// Delete multiple documents based on the passed document selectors. /// A document selector is either the document ID or the document Key. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collectionName"></param> /// <param name="selectors"></param> /// <param name="query"></param> /// <returns></returns> public virtual async Task <DeleteDocumentsResponse <T> > DeleteDocumentsAsync <T>( string collectionName, IList <string> selectors, DeleteDocumentsQuery query = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(selectors, new ApiClientSerializationOptions(false, false)); using (var response = await _client.DeleteAsync(uri, content)) { if (response.IsSuccessStatusCode) { if (query != null && query.Silent.HasValue && query.Silent.Value) { return(DeleteDocumentsResponse <T> .Empty()); } else { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <DeleteDocumentsResponse <T> >(stream)); } } throw await GetApiErrorException(response); } }
internal List<FailedDocument> DeleteDocuments(ICollection<string> documentKeys, bool noResponse) { List<JSONDocument> documents = new List<JSONDocument>(); foreach (string documentKey in documentKeys) { if (documentKey != null) { JSONDocument jdoc = new JSONDocument(); jdoc.Key = documentKey; documents.Add(jdoc); } //else // throw new ArgumentException("Document key cannot be an empty string or null"); } DeleteDocumentsOperation deleteDocumentsOperation = new DeleteDocumentsOperation(); deleteDocumentsOperation.Documents = documents.Cast<IJSONDocument>().ToList(); deleteDocumentsOperation.Database = _database.DatabaseName; deleteDocumentsOperation.Collection = _collectionName; deleteDocumentsOperation.NoResponse = noResponse; DeleteDocumentsResponse deleteDocumentsResponse = (DeleteDocumentsResponse)_database.ExecutionMapper.DeleteDocuments(deleteDocumentsOperation); if (!deleteDocumentsResponse.IsSuccessfull) { if (deleteDocumentsResponse.FailedDocumentsList == null || deleteDocumentsResponse.FailedDocumentsList.Count == 0) { throw new DataException(ErrorMessages.GetErrorMessage(deleteDocumentsResponse.ErrorCode, deleteDocumentsResponse.ErrorParams)); } return deleteDocumentsResponse.FailedDocumentsList; } return new List<FailedDocument>(); }
public override DeleteDocumentsResponse <T> ReadJson(JsonReader reader, Type objectType, DeleteDocumentsResponse <T> existingValue, bool hasExistingValue, JsonSerializer serializer) { List <DeleteDocumentResponse <T> > returnValues = new List <DeleteDocumentResponse <T> >(); if (reader.TokenType == JsonToken.StartArray) { JArray jArray = JArray.Load(reader); foreach (JToken token in jArray) { if (token.Children <JProperty>().Any(x => x.Name == "_id")) { //JsonReader copyReaderForObject = token.CreateReaderWithSettings(reader); //returnValues.Add(serializer.Deserialize<PostDocumentResponse<T>>(copyReaderForObject)); returnValues.Add(token.ToObject <DeleteDocumentResponse <T> >()); } else { returnValues.Add(new DeleteDocumentResponse <T>(token.ToObject <ApiResponse>())); } } } return(new DeleteDocumentsResponse <T>(returnValues)); }
public override void WriteJson(JsonWriter writer, DeleteDocumentsResponse <T> value, JsonSerializer serializer) { throw new NotImplementedException(); }