Exemple #1
0
        /// <summary>
        /// Partially updates the document identified by document-handle.
        /// The body of the request must contain a JSON document with the
        /// attributes to patch(the patch document). All attributes from the
        /// patch document will be added to the existing document if they do not
        /// yet exist, and overwritten in the existing document if they do exist
        /// there.
        /// PATCH/_api/document/{document-handle}
        /// </summary>
        /// <typeparam name="T">Type of the patch object used to partially update a document.</typeparam>
        /// <typeparam name="U">Type of the returned document, only applies when
        /// <see cref="PatchDocumentQuery.ReturnNew"/> or <see cref="PatchDocumentQuery.ReturnOld"/>
        /// are used.</typeparam>
        /// <param name="documentId"></param>
        /// <param name="body"></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 <PatchDocumentResponse <U> > PatchDocumentAsync <T, U>(
            string documentId,
            T body,
            PatchDocumentQuery query = null,
            ApiClientSerializationOptions serializationOptions = null)
        {
            ValidateDocumentId(documentId);
            string uriString = _docApiPath + "/" + documentId;

            if (query != null)
            {
                uriString += "?" + query.ToQueryString();
            }
            var content = GetContent(body, serializationOptions);

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

                    return(DeserializeJsonFromStream <PatchDocumentResponse <U> >(stream));
                }
                throw await GetApiErrorException(response);
            }
        }
Exemple #2
0
        /// <summary>
        /// Partially updates the document identified by document-handle.
        /// The body of the request must contain a JSON document with the
        /// attributes to patch(the patch document). All attributes from the
        /// patch document will be added to the existing document if they do not
        /// yet exist, and overwritten in the existing document if they do exist
        /// there.
        /// PATCH/_api/document/{document-handle}
        /// </summary>
        /// <typeparam name="T">Type of the patch object used to partially update a document.</typeparam>
        /// <typeparam name="U">Type of the returned document, only applies when
        /// <see cref="PatchDocumentQuery.ReturnNew"/> or <see cref="PatchDocumentQuery.ReturnOld"/>
        /// are used.</typeparam>
        /// <param name="collectionName"></param>
        /// <param name="documentKey"></param>
        /// <param name="body"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public virtual async Task <PatchDocumentResponse <U> > PatchDocumentAsync <T, U>(
            string collectionName,
            string documentKey,
            T body,
            PatchDocumentQuery query = null)
        {
            string documentHandle = WebUtility.UrlEncode(collectionName) +
                                    "/" + WebUtility.UrlEncode(documentKey);

            return(await PatchDocumentAsync <T, U>(documentHandle, body, query));
        }
Exemple #3
0
        /// <summary>
        /// Partially updates the document identified by document-handle.
        /// The body of the request must contain a JSON document with the
        /// attributes to patch(the patch document). All attributes from the
        /// patch document will be added to the existing document if they do not
        /// yet exist, and overwritten in the existing document if they do exist
        /// there.
        /// PATCH/_api/document/{document-handle}
        /// </summary>
        /// <typeparam name="T">Type of the patch object used to partially update a document.</typeparam>
        /// <typeparam name="U">Type of the returned document, only applies when
        /// <see cref="PatchDocumentQuery.ReturnNew"/> or <see cref="PatchDocumentQuery.ReturnOld"/>
        /// are used.</typeparam>
        /// <param name="collectionName"></param>
        /// <param name="documentKey"></param>
        /// <param name="body"></param>
        /// <param name="query"></param>
        /// <param name="headers">The <see cref="DocumentHeaderProperties"/> values.</param>
        /// <returns></returns>
        public virtual async Task <PatchDocumentResponse <U> > PatchDocumentAsync <T, U>(
            string collectionName,
            string documentKey,
            T body,
            PatchDocumentQuery query         = null,
            DocumentHeaderProperties headers = null)
        {
            string documentHandle = WebUtility.UrlEncode(collectionName) +
                                    "/" + WebUtility.UrlEncode(documentKey);

            return(await PatchDocumentAsync <T, U>(documentHandle, body, query, headers : headers).ConfigureAwait(false));
        }