/// <summary> /// Replace multiple documents. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collectionName"></param> /// <param name="documents"></param> /// <param name="query"></param> /// <param name="serializationOptions">The serialization options. When the value is null the /// the serialization options should be provided by the serializer, otherwise the given options should be used.</param> /// <returns></returns> public virtual async Task <PutDocumentsResponse <T> > PutDocumentsAsync <T>( string collectionName, IList <T> documents, PutDocumentsQuery query = null, ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(documents, serializationOptions); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { if (query != null && query.Silent.HasValue && query.Silent.Value) { return(PutDocumentsResponse <T> .Empty()); } else { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PutDocumentsResponse <T> >(stream)); } } throw await GetApiErrorException(response); } }
/// <summary> /// Replace multiple documents. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="collectionName"></param> /// <param name="documents"></param> /// <param name="options"></param> /// <returns></returns> public async Task <PostDocumentsResponse <T> > PutDocumentsAsync <T>(string collectionName, IList <T> documents, PutDocumentsQuery query = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetStringContent(documents, false, false); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostDocumentsResponse <T> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Replace a document. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="documentId"></param> /// <param name="doc"></param> /// <param name="opts"></param> /// <returns></returns> public async Task <PostDocumentResponse <T> > PutDocumentAsync <T>(string documentId, T doc, PutDocumentsQuery opts = null) { ValidateDocumentId(documentId); string uri = _docApiPath + "/" + documentId; if (opts != null) { uri += "?" + opts.ToQueryString(); } var content = GetStringContent(doc, false, false); using (var response = await _client.PutAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PostDocumentResponse <T> >(stream)); } throw await GetApiErrorException(response); } }