public async Task <RetrieveMultipleResponse> RetrieveMultipleAsync(FetchXmlExpression fetchXml) { string entityCollection = WebApiMetadata.GetEntitySetName(fetchXml.LogicalName); var retrieveOptions = new RetrieveOptions { FetchXml = fetchXml }; return(await RetrieveMultipleAsync(entityCollection, retrieveOptions)); }
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)); }
public async Task <Entity> RetrieveAsync(string entityName, Guid entityId, params string[] properties) { string entityCollection = WebApiMetadata.GetEntitySetName(entityName); string fullUrl = ApiUrl + entityCollection + entityId.ToString("P"); if (properties?.Any() ?? false) { fullUrl += "?$select=" + string.Join(",", properties); } var request = new HttpRequestMessage(new HttpMethod("GET"), fullUrl); HttpResponseMessage response = await Authorization.GetHttpClient().SendAsync(request); ResponseValidator.EnsureSuccessStatusCode(response); string data = await response.Content.ReadAsStringAsync(); JObject result = JObject.Parse(data); Entity entity = ResponseAttributeFormatter.FormatEntityResponse(result); entity.LogicalName = entityName; entity.Id = entityId; return(entity); }