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); }
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); }
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)); }
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); }
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); }
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)); }