Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Delete a document based on its document ID.
        /// </summary>
        /// <param name="documentId"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public async Task <DeleteDocumentResponse <T> > DeleteDocumentAsync <T>(string documentId, DeleteDocumentsQuery query = null)
        {
            ValidateDocumentId(documentId);
            string uri = _docApiPath + "/" + documentId;

            if (query != null)
            {
                uri += "?" + query.ToQueryString();
            }
            using (var response = await _client.DeleteAsync(uri))
            {
                if (response.IsSuccessStatusCode)
                {
                    var stream = await response.Content.ReadAsStreamAsync();

                    var responseModel = DeserializeJsonFromStream <DeleteDocumentResponse <T> >(stream);
                    return(responseModel);
                }
                throw await GetApiErrorException(response);
            }
        }
Beispiel #3
0
        /// <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="options"></param>
        /// <returns></returns>
        public 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 = GetStringContent(selectors, false, false);

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

                    var responseModel = DeserializeJsonFromStream <DeleteDocumentsResponse <T> >(stream);
                    return(responseModel);
                }
                throw await GetApiErrorException(response);
            }
        }