public int AddCreate(string entitySetName, string jsonData) { return(this.AddContent( CrmClient.BuildRequestUrl( entitySetName: entitySetName), "POST", jsonData)); }
public int AddDelete(string entitySetName, Guid itemId) { return(this.AddContent( CrmClient.BuildRequestUrl( entitySetName: entitySetName, itemId: itemId), "DELETE")); }
public static async Task <IEntityMetadata> GetEntityMetadataAsync(this CrmClient crmClient, string logicalName, bool expandAttributes = true) { return((await crmClient.List( entitySetName: "EntityDefinitions", filter: $"LogicalName eq '{logicalName}'", select: "MetadataId, LogicalName, DisplayName, EntitySetName, PrimaryIdAttribute, PrimaryNameAttribute", convert: (metadataJson, eventArgs) => { return new EntityMetadata(metadataJson); }, expand: expandAttributes ? "Attributes" : null)).FirstOrDefault()); }
public int AddUpdate(string entitySetName, Guid itemId, string jsonData) { return(this.AddContent( CrmClient.BuildRequestUrl( entitySetName: entitySetName, itemId: itemId), "PATCH", jsonData)); }
public int AddRead(string entitySetName, string subEntitySetName = null, Guid?itemId = null, string fetchXml = null, string select = null, string inlineCount = null, string filter = null, int?top = null, string expand = null, string expandSelect = null, string expandFilter = null) { return(this.AddContent( CrmClient.BuildRequestUrl( entitySetName: entitySetName, subEntitySetName: subEntitySetName, itemId: itemId, fetchXml: fetchXml, select: select, inlineCount: inlineCount, filter: filter, expand: expand, expandSelect: expandSelect, expandFilter: expandFilter, top: top), "GET")); }
internal static string BuildRequestUrl( string entitySetName, string subEntitySetName = null, Guid?itemId = null, string fetchXml = null, string select = null, string inlineCount = null, string filter = null, string orderby = null, string expand = null, int?top = null, string expandSelect = null, string expandFilter = null) { select = CrmClient.RemoveWhiteSpaces(select); string requestUrl = $"{entitySetName}"; List <string> queryParameters = new List <string>(); Func <string, string, bool, bool> queryIfProvided = (format, parameter, escaped) => { if (!string.IsNullOrEmpty(parameter)) { queryParameters.Add(string.Format(format, escaped ? Uri.EscapeDataString(parameter) : parameter)); return(true); } return(false); }; requestUrl += (itemId == null) ? string.Empty : $"({((Guid)itemId).ToCleanString()})"; requestUrl += string.IsNullOrEmpty(subEntitySetName) ? string.Empty : $"/{subEntitySetName}"; queryIfProvided.Invoke("fetchXml={0}", fetchXml, true); queryIfProvided.Invoke("$select={0}", select, false); queryIfProvided.Invoke("$inlinecount={0}", inlineCount, false); queryIfProvided.Invoke("$orderby={0}", orderby, false); queryIfProvided.Invoke("$filter={0}", filter, false); queryIfProvided.Invoke("$top={0}", top == null ? string.Empty : top.ToString(), false); if (!string.IsNullOrEmpty(expand)) { if (!string.IsNullOrEmpty(expandSelect) || !string.IsNullOrEmpty(expandFilter)) { if (string.IsNullOrEmpty(expandSelect)) { expand = $"{expand}($filter={expandFilter})"; } else if (string.IsNullOrEmpty(expandFilter)) { expand = $"{expand}($select={expandSelect})"; } else { expand = $"{expand}($select={expandSelect}&$filter={expandFilter})"; } } queryParameters.Add($"$expand={expand}"); } if (queryParameters.Count > 0) { requestUrl = $"{requestUrl}?{string.Join("&", queryParameters)}"; } queryParameters.Destroy(); return(requestUrl); }
public static async Task <IEnumerable <IEntityMetadata> > GetAllEntityMetadataAsync(this CrmClient crmClient, bool expandAttributes = true) { JsonArrayResponse metadataRecordsResponse = null; List <IEntityMetadata> metadataRecords = null; do { metadataRecordsResponse = await crmClient.List( entitySetName : "EntityDefinitions", select : "MetadataId, LogicalName, DisplayName, EntitySetName, PrimaryIdAttribute, PrimaryNameAttribute", previousResponse : metadataRecordsResponse); foreach (var metadataJson in metadataRecordsResponse) { metadataRecords.Add(new EntityMetadata(metadataJson)); } metadataRecordsResponse.Clear(); }while (!string.IsNullOrEmpty(metadataRecordsResponse.NextLink)); metadataRecordsResponse.Destroy(); return(metadataRecords); }