コード例 #1
0
ファイル: WebApi.cs プロジェクト: teamviewer/Xrm.Crm.WebApi
        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);
        }
コード例 #2
0
ファイル: WebApi.cs プロジェクト: teamviewer/Xrm.Crm.WebApi
        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);
        }
コード例 #3
0
ファイル: WebApi.cs プロジェクト: teamviewer/Xrm.Crm.WebApi
        public async Task <Guid> CreateAsync(Entity entity)
        {
            string  fullUrl = ApiUrl + WebApiMetadata.GetEntitySetName(entity.LogicalName);
            JObject jObject = RequestEntityParser.EntityToJObject(entity, WebApiMetadata);
            var     request = new HttpRequestMessage(new HttpMethod("Post"), fullUrl)
            {
                Content = new StringContent(JsonConvert.SerializeObject(jObject), Encoding.UTF8, "application/json")
            };

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

            ResponseValidator.EnsureSuccessStatusCode(response);

            return(GetEntityIdFromResponse(fullUrl, response));
        }
コード例 #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);
        }
コード例 #5
0
ファイル: WebApi.cs プロジェクト: teamviewer/Xrm.Crm.WebApi
        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);
        }
コード例 #6
0
        public JProperty GetUpdateContent(WebApiMetadata webApiMetadata)
        {
            var jObject = new JObject();

            jObject["@odata.type"] = $"Microsoft.Dynamics.CRM.{entityDefinition.LogicalName}";
            jObject[entityDefinition.PrimaryIdAttribute] = Target.Id.ToString("D");

            if (UpdateContent == null)
            {
                return(new JProperty("UpdateContent", jObject));
            }

            foreach (KeyValuePair <string, object> attribute in UpdateContent)
            {
                if (jObject.ContainsKey(attribute.Key))
                {
                    continue;
                }

                jObject.Add(RequestEntityParser.GetJTokenFromAttribute(attribute.Key, attribute.Value, webApiMetadata));
            }

            return(new JProperty("UpdateContent", jObject));
        }