static async Task UpdateBooleanAttribute(CustomerAccount customerAccount, IApiContext apiContext, string attributeName, bool attributeValue) { var attributeResource = new AttributeResource(apiContext); var attribute = await attributeResource.GetAttributeAsync(attributeName); var customerAttributeResource = new CustomerAttributeResource(apiContext); var customerAttribute = await customerAttributeResource.GetAccountAttributeAsync(customerAccount.Id, attribute.AttributeFQN) ?? new CustomerAttribute { AttributeDefinitionId = attribute.Id, FullyQualifiedName = attribute.AttributeFQN }; attribute.AttributeFQN = attribute.AttributeFQN.ToLower(); customerAttribute.Values = new List <object> { attributeValue }; if (customerAccount.Attributes.All(s => s.AttributeDefinitionId != attribute.Id)) { await customerAttributeResource.AddAccountAttributeAsync(customerAttribute, customerAccount.Id, attribute.AttributeFQN); } else { await customerAttributeResource.UpdateAccountAttributeAsync(customerAttribute, customerAccount.Id, attribute.AttributeFQN); } }
public static async Task <bool> IsRewardsAssigned(this CustomerAccount customerAccount, IApiContext apiContext) { var attributeResource = new AttributeResource(apiContext); var attribute = await attributeResource.GetAttributeAsync(AttributeConstants.RewardsAssigned); var customerAttributeResource = new CustomerAttributeResource(apiContext); var attributeCustomer = await customerAttributeResource.GetAccountAttributeAsync(customerAccount.Id, attribute.AttributeFQN); return(attributeCustomer != null && attributeCustomer.Values.Any(a => a.Equals(true))); }
static async Task <bool> CheckBooleanAttributeIsSet(CustomerAccount customerAccount, IApiContext apiContext, string attributeName) { var attributeResource = new AttributeResource(apiContext); var attribute = await attributeResource.GetAttributeAsync(attributeName); attribute.AttributeFQN = attribute.AttributeFQN.ToLower(); var customerAttributeResource = new CustomerAttributeResource(apiContext); var attributeCustomer = await customerAttributeResource.GetAccountAttributeAsync(customerAccount.Id, attribute.AttributeFQN); return(attributeCustomer != null && attributeCustomer.Values.Any(a => a.Equals(true))); }