/// <summary> /// Partially updates documents, the documents to update are specified /// by the _key attributes in the body objects. All attributes from the /// patch documents will be added to the existing documents if they do /// not yet exist, and overwritten in the existing documents if they do /// exist there. /// Setting an attribute value to null in the patch documents will cause a /// value of null to be saved for the attribute by default. /// If ignoreRevs is false and there is a _rev attribute in a /// document in the body and its value does not match the revision of /// the corresponding document in the database, the precondition is /// violated. /// PATCH /_api/document/{collection} /// </summary> /// <typeparam name="T">Type of the patch object used to partially update documents.</typeparam> /// <typeparam name="U">Type of the returned documents, only applies when /// <see cref="PatchDocumentsQuery.ReturnNew"/> or <see cref="PatchDocumentsQuery.ReturnOld"/> /// are used.</typeparam> /// <param name="collectionName"></param> /// <param name="patches"></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 <PatchDocumentsResponse <U> > PatchDocumentsAsync <T, U>( string collectionName, IList <T> patches, PatchDocumentsQuery query = null, ApiClientSerializationOptions serializationOptions = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(patches, serializationOptions); using (var response = await _client.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) { if (query != null && query.Silent.HasValue && query.Silent.Value) { return(PatchDocumentsResponse <U> .Empty()); } else { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PatchDocumentsResponse <U> >(stream)); } } throw await GetApiErrorException(response); } }
/// <summary> /// Updates the data of the specific vertex in the collection. /// PATCH/_api/gharial/{graph}/vertex/{collection}/{vertex} /// </summary> /// <typeparam name="T">Type of the patch object</typeparam> /// <typeparam name="U">Type of the returned document, only applies when /// <see cref="PatchVertexQuery.ReturnNew"/> or <see cref="PatchVertexQuery.ReturnOld"/> /// are used.</typeparam> /// <param name="graphName"></param> /// <param name="collectionName"></param> /// <param name="vertexKey"></param> /// <param name="body"></param> /// <param name="query"></param> /// <returns></returns> public async Task <PatchVertexResponse <U> > PatchVertexAsync <T, U>( string graphName, string collectionName, string vertexKey, T body, PatchVertexQuery query = null) { string uri = _graphApiPath + '/' + WebUtility.UrlEncode(graphName) + "/vertex/" + WebUtility.UrlEncode(collectionName) + "/" + WebUtility.UrlEncode(vertexKey); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(body, false, false); using (var response = await _transport.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PatchVertexResponse <U> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Updates the data of the specific vertex based on its document ID. /// </summary> /// <exception cref="ArgumentException">Provided document ID is invalid.</exception> /// <typeparam name="T">Type of the patch object</typeparam> /// <typeparam name="U">Type of the returned document, only applies when /// <see cref="PatchVertexQuery.ReturnNew"/> or <see cref="PatchVertexQuery.ReturnOld"/> /// are used.</typeparam> /// <param name="graphName">The name of the graph in which to update the vertex.</param> /// <param name="documentId">The document ID of the vertex to update.</param> /// <param name="body"></param> /// <param name="query"></param> /// <returns></returns> public virtual async Task <PatchVertexResponse <U> > PatchVertexAsync <T, U>( string graphName, string documentId, T body, PatchVertexQuery query = null) { ValidateDocumentId(documentId); string uri = _graphApiPath + '/' + WebUtility.UrlEncode(graphName) + "/vertex/" + documentId; if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(body, new ApiClientSerializationOptions(false, false)); using (var response = await _transport.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PatchVertexResponse <U> >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Partially updates documents, the documents to update are specified /// by the _key attributes in the body objects.The body of the /// request must contain a JSON array of document updates with the /// attributes to patch(the patch documents). All attributes from the /// patch documents will be added to the existing documents if they do /// not yet exist, and overwritten in the existing documents if they do /// exist there. /// Setting an attribute value to null in the patch documents will cause a /// value of null to be saved for the attribute by default. /// If ignoreRevs is false and there is a _rev attribute in a /// document in the body and its value does not match the revision of /// the corresponding document in the database, the precondition is /// violated. /// PATCH/_api/document/{collection} /// </summary> /// <typeparam name="T">Type of the patch object used to partially update documents.</typeparam> /// <typeparam name="U">Type of the returned documents, only applies when /// <see cref="PatchDocumentsQuery.ReturnNew"/> or <see cref="PatchDocumentsQuery.ReturnOld"/> /// are used.</typeparam> /// <param name="collectionName"></param> /// <param name="patches"></param> /// <param name="query"></param> /// <returns></returns> public async Task <IList <PatchDocumentsResponse <U> > > PatchDocumentsAsync <T, U>( string collectionName, IList <T> patches, PatchDocumentsQuery query = null) { string uri = _docApiPath + "/" + WebUtility.UrlEncode(collectionName); if (query != null) { uri += "?" + query.ToQueryString(); } var content = GetContent(patches, false, false); using (var response = await _client.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <IList <PatchDocumentsResponse <U> > >(stream)); } throw await GetApiErrorException(response); } }
/// <summary> /// Partially update an existing user. /// You need server access level Administrate in order to execute this REST call. /// Additionally, a user can change his/her own data. /// </summary> /// <param name="username">The name of the user.</param> /// <param name="body">The user information used for to replace operation.</param> /// <returns></returns> public virtual async Task <PatchUserResponse> PatchUserAsync(string username, PatchUserBody body) { string uri = _userApiPath + '/' + username; var content = GetContent(body, new ApiClientSerializationOptions(true, true)); using (var response = await _client.PatchAsync(uri, content)) { if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStreamAsync(); return(DeserializeJsonFromStream <PatchUserResponse>(stream)); } throw await GetApiErrorException(response); } }