protected bool ConditionCustomerAttribute(CustomerAction.ActionCondition condition, Customer customer)
        {
            bool cond = false;

            if (customer != null)
            {
                var _genericAttributes = _customerService.GetCustomerById(customer.Id).GenericAttributes;
                if (condition.Condition == CustomerActionConditionEnum.AllOfThem)
                {
                    var customCustomerAttributes = _genericAttributes.FirstOrDefault(x => x.Key == "CustomCustomerAttributes");
                    if (customCustomerAttributes != null)
                    {
                        if (!String.IsNullOrEmpty(customCustomerAttributes.Value))
                        {
                            var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(customCustomerAttributes.Value);
                            cond = true;
                            foreach (var item in condition.CustomCustomerAttributes)
                            {
                                var _fields = item.RegisterField.Split(':');
                                if (_fields.Count() > 1)
                                {
                                    if (selectedValues.Where(x => x.CustomerAttributeId == _fields.FirstOrDefault() && x.Id == _fields.LastOrDefault()).Count() == 0)
                                    {
                                        cond = false;
                                    }
                                }
                                else
                                {
                                    cond = false;
                                }
                            }
                        }
                    }
                }
                if (condition.Condition == CustomerActionConditionEnum.OneOfThem)
                {
                    var customCustomerAttributes = _genericAttributes.FirstOrDefault(x => x.Key == "CustomCustomerAttributes");
                    if (customCustomerAttributes != null)
                    {
                        if (!String.IsNullOrEmpty(customCustomerAttributes.Value))
                        {
                            var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(customCustomerAttributes.Value);
                            foreach (var item in condition.CustomCustomerAttributes)
                            {
                                var _fields = item.RegisterField.Split(':');
                                if (_fields.Count() > 1)
                                {
                                    if (selectedValues.Where(x => x.CustomerAttributeId == _fields.FirstOrDefault() && x.Id == _fields.LastOrDefault()).Count() > 0)
                                    {
                                        cond = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(cond);
        }
        private ReqPassChangeChangeType GetReqPassChangeChangeType(GenericAttribute entity)
        {
            if (entity == null)
            {
                return(ReqPassChangeChangeType.Unknown);
            }

            var customCustomerAttributesXml = entity.Value;

            var attrs      = _customerAttributeParser.ParseCustomerAttributes(customCustomerAttributesXml);
            var attrValues = _customerAttributeParser.ParseCustomerAttributeValues(customCustomerAttributesXml);

            var reqPassChangeAttr = attrs.SingleOrDefault(x => x.Name.Equals(RequirePasswordChangePluginCustomerAttributeNames.RequiredPasswordChange, StringComparison.OrdinalIgnoreCase));

            if (reqPassChangeAttr == null)
            {
                return(ReqPassChangeChangeType.Removed);
            }

            var reqPassChangeAttValue = attrValues.SingleOrDefault(x => x.CustomerAttributeId == reqPassChangeAttr.Id);

            if (reqPassChangeAttValue == null)
            {
                // unsure how we landed in this block
                return(ReqPassChangeChangeType.Removed);
            }

            if (reqPassChangeAttValue.Name.Equals(RequirePasswordChangePluginCustomerAttributeValueNames.RequiredPasswordChangeYes, StringComparison.OrdinalIgnoreCase))
            {
                return(ReqPassChangeChangeType.Added);
            }
            else if (reqPassChangeAttValue.Name.Equals(RequirePasswordChangePluginCustomerAttributeValueNames.RequiredPasswordChangeNo, StringComparison.OrdinalIgnoreCase))
            {
                return(ReqPassChangeChangeType.Removed);
            }
            else
            {
                return(ReqPassChangeChangeType.Unknown);
            }
        }
        public virtual IList <CustomerAttributeModel> PrepareCustomCustomerAttributes(Customer customer, string overrideAttributesXml = "")
        {
            if (customer == null)
            {
                throw new ArgumentNullException("customer");
            }

            var result = new List <CustomerAttributeModel>();

            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in customerAttributes)
            {
                var attributeModel = new CustomerAttributeModel
                {
                    Id                   = attribute.Id,
                    Name                 = attribute.GetLocalized(x => x.Name),
                    IsRequired           = attribute.IsRequired,
                    AttributeControlType = attribute.AttributeControlType,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id);
                    foreach (var attributeValue in attributeValues)
                    {
                        var valueModel = new CustomerAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.GetLocalized(x => x.Name),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(valueModel);
                    }
                }

                //set already selected attributes
                var selectedAttributesXml = !String.IsNullOrEmpty(overrideAttributesXml) ?
                                            overrideAttributesXml :
                                            customer.GetAttribute <string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (!String.IsNullOrEmpty(selectedAttributesXml))
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedAttributesXml);
                        foreach (var attributeValue in selectedValues)
                        {
                            foreach (var item in attributeModel.Values)
                            {
                                if (attributeValue.Id == item.Id)
                                {
                                    item.IsPreSelected = true;
                                }
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //do nothing
                    //values are already pre-set
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    if (!String.IsNullOrEmpty(selectedAttributesXml))
                    {
                        var enteredText = _customerAttributeParser.ParseValues(selectedAttributesXml, attribute.Id);
                        if (enteredText.Any())
                        {
                            attributeModel.DefaultValue = enteredText[0];
                        }
                    }
                }
                break;

                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.Datepicker:
                case AttributeControlType.FileUpload:
                default:
                    //not supported attribute control types
                    break;
                }

                result.Add(attributeModel);
            }


            return(result);
        }
        public async Task <IList <CustomerAttributeModel> > Handle(GetCustomAttributes request, CancellationToken cancellationToken)
        {
            var result = new List <CustomerAttributeModel>();

            var customerAttributes = await _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in customerAttributes)
            {
                var attributeModel = new CustomerAttributeModel
                {
                    Id                   = attribute.Id,
                    Name                 = attribute.GetTranslation(x => x.Name, request.Language.Id),
                    IsRequired           = attribute.IsRequired,
                    IsReadOnly           = attribute.IsReadOnly,
                    AttributeControlType = attribute.AttributeControlTypeId,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = attribute.CustomerAttributeValues;
                    foreach (var attributeValue in attributeValues)
                    {
                        var valueModel = new CustomerAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.GetTranslation(x => x.Name, request.Language.Id),
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(valueModel);
                    }
                }

                //set already selected attributes
                var selectedAttributes = request.OverrideAttributes ?? request.Customer.Attributes;

                switch (attribute.AttributeControlTypeId)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                case AttributeControlType.Checkboxes:
                {
                    if (selectedAttributes.Any())
                    {
                        //clear default selection
                        foreach (var item in attributeModel.Values)
                        {
                            item.IsPreSelected = false;
                        }

                        //select new values
                        var selectedValues = await _customerAttributeParser.ParseCustomerAttributeValues(selectedAttributes);

                        foreach (var attributeValue in selectedValues)
                        {
                            if (attributeModel.Id == attributeValue.CustomerAttributeId)
                            {
                                foreach (var item in attributeModel.Values)
                                {
                                    if (attributeValue.Id == item.Id)
                                    {
                                        item.IsPreSelected = true;
                                    }
                                }
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //do nothing
                    //values are already pre-set
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    if (selectedAttributes.Any())
                    {
                        var enteredText = selectedAttributes.Where(x => x.Key == attribute.Id).Select(x => x.Value).ToList();
                        if (enteredText.Any())
                        {
                            attributeModel.DefaultValue = enteredText[0];
                        }
                    }
                }
                break;

                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.Datepicker:
                case AttributeControlType.FileUpload:
                default:
                    //not supported attribute control types
                    break;
                }

                result.Add(attributeModel);
            }


            return(result);
        }
Esempio n. 5
0
 /// <summary>
 /// Get customer attribute values
 /// </summary>
 /// <param name="attributesXml">Attributes in XML format</param>
 /// <returns>Customer attribute values</returns>
 IList <CustomerAttributeValue> ParseCustomerAttributeValues(string attributesXml)
 {
     return(_customerAttributeParser.ParseCustomerAttributeValues(attributesXml));
 }
Esempio n. 6
0
        protected virtual void PrepareCustomerAttributeModel(CustomerModel model, Customer customer)
        {
            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in customerAttributes)
            {
                var attributeModel = new CustomerModel.CustomerAttributeModel
                {
                    Id                   = attribute.Id,
                    Name                 = attribute.Name,
                    IsRequired           = attribute.IsRequired,
                    AttributeControlType = attribute.AttributeControlType,
                };

                if (attribute.ShouldHaveValues())
                {
                    //values
                    var attributeValues = _customerAttributeService.GetCustomerAttributeValues(attribute.Id);
                    foreach (var attributeValue in attributeValues)
                    {
                        var attributeValueModel = new CustomerModel.CustomerAttributeValueModel
                        {
                            Id            = attributeValue.Id,
                            Name          = attributeValue.Name,
                            IsPreSelected = attributeValue.IsPreSelected
                        };
                        attributeModel.Values.Add(attributeValueModel);
                    }
                }


                //set already selected attributes
                if (customer != null)
                {
                    var selectedCustomerAttributes = customer.GetAttribute <string>(SystemCustomerAttributeNames.CustomCustomerAttributes, _genericAttributeService);
                    switch (attribute.AttributeControlType)
                    {
                    case AttributeControlType.DropdownList:
                    case AttributeControlType.RadioList:
                    case AttributeControlType.Checkboxes:
                    {
                        if (!string.IsNullOrEmpty(selectedCustomerAttributes))
                        {
                            //clear default selection
                            foreach (var item in attributeModel.Values)
                            {
                                item.IsPreSelected = false;
                            }

                            //select new values
                            var selectedValues = _customerAttributeParser.ParseCustomerAttributeValues(selectedCustomerAttributes);
                            foreach (var attributeValue in selectedValues)
                            {
                                foreach (var item in attributeModel.Values)
                                {
                                    if (attributeValue.Id == item.Id)
                                    {
                                        item.IsPreSelected = true;
                                    }
                                }
                            }
                        }
                    }
                    break;

                    case AttributeControlType.ReadonlyCheckboxes:
                    {
                        //do nothing
                        //values are already pre-set
                    }
                    break;

                    case AttributeControlType.TextBox:
                    case AttributeControlType.MultilineTextbox:
                    {
                        if (!string.IsNullOrEmpty(selectedCustomerAttributes))
                        {
                            var enteredText = _customerAttributeParser.ParseValues(selectedCustomerAttributes, attribute.Id);
                            if (enteredText.Any())
                            {
                                attributeModel.DefaultValue = enteredText[0];
                            }
                        }
                    }
                    break;

                    case AttributeControlType.Datepicker:
                    case AttributeControlType.ColorSquares:
                    case AttributeControlType.ImageSquares:
                    case AttributeControlType.FileUpload:
                    default:
                        //not supported attribute control types
                        break;
                    }
                }

                model.CustomerAttributes.Add(attributeModel);
            }
        }