public async Task CreateCompanyPropertyAsync(CrmProperty companyProperty, CancellationToken cancellationToken = default) { // this isn't a field you set on CREATE companyProperty.CreatedAt = null; await CreateCrmPropertyAsync("company", companyProperty, cancellationToken); }
public static T FilterEnumerationPropertyValues <T>(this T domainModel, CrmProperty property) { var validPropertyValues = property.Options?.Select(o => o.Label) ?? Enumerable.Empty <string>(); var currentValues = GetDomainModelProperties(domainModel) .Where(p => (p.JsonPropertyAttribute?.PropertyName ?? p.PropertyInfo.Name.ToLowerInvariant()) == property.Name) .Select(p => p.PropertyInfo.GetValue(domainModel)?.ToString()) .SelectMany(s => s?.Split(';') ?? Array.Empty <string>()); TrySetValue(domainModel, property.Name, string.Join(';', currentValues.Intersect(validPropertyValues))); return(domainModel); }
private async Task CreateCrmPropertyAsync(string endpoint, CrmProperty contactProperty, CancellationToken cancellationToken) { // this isn't a field you set on CREATE contactProperty.CreatedAt = null; var json = JsonConvert.SerializeObject(contactProperty, Formatting.Indented, new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy(), }, NullValueHandling = NullValueHandling.Ignore, }); using var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await RequestWithRetriesAsync( async cancellationToken => await m_client.PostAsync($"/crm/v3/properties/{endpoint}", content, cancellationToken), cancellationToken); await response.EnsureSuccessStatusCodeWithResponseBodyInException(); }