Ejemplo n.º 1
0
        public async Task DisassociateAsync(Entity entity, string navigationProperty)
        {
            string fullUrl = ApiUrl + RequestEntityParser.GetEntityApiUrl(entity, WebApiMetadata) + "/" + navigationProperty + "/$ref";
            var    request = new HttpRequestMessage(new HttpMethod("DELETE"), fullUrl);
            HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request);

            ResponseValidator.EnsureSuccessStatusCode(response);
        }
Ejemplo n.º 2
0
        public async Task DeleteAsync(Entity entity)
        {
            string fullUrl = ApiUrl + RequestEntityParser.GetEntityApiUrl(entity, WebApiMetadata);
            var    request = new HttpRequestMessage(new HttpMethod("Delete"), fullUrl)
            {
                Content = new StringContent("{}", Encoding.UTF8, "application/json")
            };

            HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request);

            ResponseValidator.EnsureSuccessStatusCode(response);
        }
Ejemplo n.º 3
0
        public async Task UpsertAsync(Entity entity, UpsertOptions upsertOptions = UpsertOptions.None)
        {
            string  fullUrl = ApiUrl + RequestEntityParser.GetEntityApiUrl(entity, WebApiMetadata);
            JObject jObject = RequestEntityParser.EntityToJObject(entity, WebApiMetadata);
            var     request = new HttpRequestMessage(new HttpMethod("PATCH"), fullUrl)
            {
                Content = new StringContent(JsonConvert.SerializeObject(jObject), Encoding.UTF8, "application/json")
            };

            if (upsertOptions == UpsertOptions.OnlyUpdate)
            {
                request.Headers.Add("If-Match", "*");
            }

            if (upsertOptions == UpsertOptions.OnlyCreate)
            {
                request.Headers.Add("If-None-Match", "*");
            }

            HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request);

            ResponseValidator.EnsureSuccessStatusCode(response);
        }
Ejemplo n.º 4
0
        internal override string GetBatchString(BatchRequest batchRequest, WebApi webApi, int?lastContentId)
        {
            var entityUrl    = lastContentId != null ? "$" + lastContentId.ToString() : webApi.ApiUrl + RequestEntityParser.GetEntityApiUrl(EntityToCreate, webApi.WebApiMetadata);
            var jObject      = RequestEntityParser.EntityToJObject(EntityToCreate, webApi.WebApiMetadata);
            var entityString = JsonConvert.SerializeObject(jObject);

            var batchString = $"--changeset_{batchRequest.ChangeSetId.ToString("N")}" + NewLine;

            batchString += $"Content-Type: application/http" + NewLine;
            batchString += $"Content-Transfer-Encoding:binary" + NewLine;
            batchString += $"Content-ID: {batchRequest.ContentId}" + NewLine + NewLine;
            batchString += $"POST {entityUrl} HTTP/1.1" + NewLine;
            batchString += $"Content-Type: application/json;type=entry" + NewLine + NewLine;
            batchString += entityString + NewLine + NewLine;
            return(batchString);
        }