Beispiel #1
0
        /// <summary>
        /// Replaces the document with the provided document ID with the one in
        /// the body, provided there is such a document and no precondition is
        /// violated.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="documentId"></param>
        /// <param name="doc"></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 <PutDocumentResponse <T> > PutDocumentAsync <T>(
            string documentId,
            T doc,
            PutDocumentQuery opts = null,
            ApiClientSerializationOptions serializationOptions = null)
        {
            ValidateDocumentId(documentId);
            string uri = _docApiPath + "/" + documentId;

            if (opts != null)
            {
                uri += "?" + opts.ToQueryString();
            }
            var content = GetContent(doc, serializationOptions);

            using (var response = await _client.PutAsync(uri, content))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    return(DeserializeJsonFromStream <PutDocumentResponse <T> >(stream));
                }
                throw await GetApiErrorException(response);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Replaces the document based on its Document ID with the one in
 /// the body, provided there is such a document and no precondition is
 /// violated.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="collectionName"></param>
 /// <param name="documentKey"></param>
 /// <param name="doc"></param>
 /// <param name="opts"></param>
 /// <returns></returns>
 public virtual Task <PutDocumentResponse <T> > PutDocumentAsync <T>(
     string collectionName,
     string documentKey,
     T doc,
     PutDocumentQuery opts = null)
 {
     return(PutDocumentAsync <T>(
                $"{WebUtility.UrlEncode(collectionName)}/{WebUtility.UrlEncode(documentKey)}",
                doc,
                opts));
 }