Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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)));
        }
Exemplo n.º 3
0
        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)));
        }