Esempio n. 1
0
        /// <summary>
        /// Prepare paged customer attribute list model
        /// </summary>
        /// <param name="searchModel">Customer attribute search model</param>
        /// <returns>Customer attribute list model</returns>
        public virtual CustomerAttributeListModel PrepareCustomerAttributeListModel(CustomerAttributeSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get customer attributes
            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes().ToPagedList(searchModel);

            //prepare list model
            var model = new CustomerAttributeListModel().PrepareToGrid(searchModel, customerAttributes, () =>
            {
                return(customerAttributes.Select(attribute =>
                {
                    //fill in model values from the entity
                    var attributeModel = attribute.ToModel <CustomerAttributeModel>();

                    //fill in additional values (not existing in the entity)
                    attributeModel.AttributeControlTypeName = _localizationService.GetLocalizedEnum(attribute.AttributeControlType);

                    return attributeModel;
                }));
            });

            return(model);
        }
        private string PrepareCustomerAttributes(RegistrationViewModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            string attributesXml = "";
            var    attributes    = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in attributes)
            {
                switch (attribute.Name)
                {
                case "Center Name":
                    //   AddAttribute(model.CenterNameRequest.Trim(), attribute, ref attributesXml);
                    break;

                case "Center Enrollment Id":
                    //   AddAttribute(model.CenterGroupIdRequest.Trim(), attribute, ref attributesXml);
                    break;


                default:
                    break;
                }
            }
            return(attributesXml);
        }
        /// <summary>
        /// Prepare paged customer attribute list model
        /// </summary>
        /// <param name="searchModel">Customer attribute search model</param>
        /// <returns>Customer attribute list model</returns>
        public virtual CustomerAttributeListModel PrepareCustomerAttributeListModel(CustomerAttributeSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get customer attributes
            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes();

            //prepare list model
            var model = new CustomerAttributeListModel
            {
                Data = customerAttributes.PaginationByRequestModel(searchModel).Select(attribute =>
                {
                    //fill in model values from the entity
                    var attributeModel = attribute.ToModel <CustomerAttributeModel>();

                    //fill in additional values (not existing in the entity)
                    attributeModel.AttributeControlTypeName = _localizationService.GetLocalizedEnum(attribute.AttributeControlType);

                    return(attributeModel);
                }),
                Total = customerAttributes.Count
            };

            return(model);
        }
Esempio n. 4
0
        public IList <string> GetAttributeWarnings(string attributesXml)
        {
            var warnings    = new List <string>();
            var attributes1 = ParseCustomerAttributes(attributesXml);
            var attributes2 = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var a2 in attributes2)
            {
                if (a2.IsRequired)
                {
                    bool found = false;
                    foreach (var a1 in attributes1)
                    {
                        if (a1.Id == a2.Id)
                        {
                            var valueStrs = ParseValues(attributesXml, a1.Id);
                            foreach (string valueStr in valueStrs)
                            {
                                if (!string.IsNullOrEmpty(valueStr))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (!found)
                    {
                        var notFoundWarning = string.Format(_localizationService.GetResource("ShoppingCart.SelectAttribute"), a2.GetLocalized(a => a.Name));
                        warnings.Add(notFoundWarning);
                    }
                }
            }
            return(warnings);
        }
        public virtual async Task <IEnumerable <CustomerAttributeModel> > PrepareCustomerAttributes()
        {
            var customerAttributes = await _customerAttributeService.GetAllCustomerAttributes();

            return(customerAttributes.Select((Func <CustomerAttribute, CustomerAttributeModel>)(x =>
            {
                var attributeModel = x.ToModel();
                attributeModel.AttributeControlTypeName = TranslateExtensions.GetTranslationEnum <Domain.Catalog.AttributeControlType>(x.AttributeControlTypeId, (ITranslationService)_translationService, (IWorkContext)_workContext);
                return attributeModel;
            })));
        }
Esempio n. 6
0
        public virtual async Task <IEnumerable <CustomerAttributeModel> > PrepareCustomerAttributes()
        {
            var customerAttributes = await _customerAttributeService.GetAllCustomerAttributes();

            return(customerAttributes.Select(x =>
            {
                var attributeModel = x.ToModel();
                attributeModel.AttributeControlTypeName = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext);
                return attributeModel;
            }));
        }
Esempio n. 7
0
        /// <summary>
        /// Validates customer attributes
        /// </summary>
        /// <param name="customAttributes">Attributes</param>
        /// <returns>Warnings</returns>
        public virtual async Task <IList <string> > GetAttributeWarnings(IList <CustomAttribute> customAttributes)
        {
            var warnings = new List <string>();

            if (customAttributes == null || !customAttributes.Any())
            {
                return(warnings);
            }

            //ensure it's our attributes
            var attributes1 = await ParseCustomerAttributes(customAttributes);

            //validate required customer attributes (whether they're chosen/selected/entered)
            var attributes2 = await _customerAttributeService.GetAllCustomerAttributes();

            foreach (var a2 in attributes2)
            {
                if (a2.IsRequired)
                {
                    bool found = false;
                    //selected customer attributes
                    foreach (var a1 in attributes1)
                    {
                        if (a1.Id == a2.Id)
                        {
                            var valuesStr = customAttributes.Where(x => x.Key == a1.Id).Select(x => x.Value);
                            foreach (var str1 in valuesStr)
                            {
                                if (!string.IsNullOrEmpty(str1.Trim()))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }

                    //if not found
                    if (!found)
                    {
                        var notFoundWarning = string.Format(_localizationService.GetResource("ShoppingCart.SelectAttribute"), a2.GetLocalized(a => a.Name, ""));

                        warnings.Add(notFoundWarning);
                    }
                }
            }

            return(warnings);
        }
        /// <summary>
        ///     Validates customer attributes
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <returns>Warnings</returns>
        public virtual IList <string> GetAttributeWarnings(string attributesXml)
        {
            var warnings = new List <string>();

            //ensure it's our attributes
            var attributes1 = ParseCustomerAttributes(attributesXml);

            //validate required customer attributes (whether they're chosen/selected/entered)
            var attributes2 = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var a2 in attributes2)
            {
                if (a2.IsRequired)
                {
                    var found = false;
                    //selected customer attributes
                    foreach (var a1 in attributes1)
                    {
                        if (a1.Id == a2.Id)
                        {
                            var valuesStr = ParseValues(attributesXml, a1.Id);
                            foreach (var str1 in valuesStr)
                            {
                                if (!String.IsNullOrEmpty(str1.Trim()))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }

                    //if not found
                    if (!found)
                    {
                        var notFoundWarning =
                            string.Format(_localizationService.GetResource("ShoppingCart.SelectAttribute"),
                                          a2.GetLocalized(a => a.Name));

                        warnings.Add(notFoundWarning);
                    }
                }
            }

            return(warnings);
        }
 public async Task<IActionResult> CustomCustomerAttributeFields()
 {
     var list = new List<Tuple<string, string>>();
     foreach (var item in await _customerAttributeService.GetAllCustomerAttributes())
     {
         if (item.AttributeControlType == AttributeControlType.Checkboxes ||
             item.AttributeControlType == AttributeControlType.DropdownList ||
             item.AttributeControlType == AttributeControlType.RadioList)
         {
             foreach (var value in item.CustomerAttributeValues)
             {
                 list.Add(Tuple.Create(string.Format("{0}:{1}", item.Id, value.Id), item.Name + "->" + value.Name));
             }
         }
     }
     var customer = list.Select(x => new { Id = x.Item1, Name = x.Item2 });
     return Json(customer);
 }
        /// <summary>
        /// Validates customer attributes
        /// </summary>
        /// <param name="selectedAttributes">Selected attributes</param>
        /// <returns>Warnings</returns>
        public virtual IList <string> GetAttributeWarnings(string selectedAttributes)
        {
            var warnings = new List <string>();

            //ensure it's our attributes
            var cva1Collection = ParseCustomerAttributes(selectedAttributes);

            //validate required checkout attributes (whether they're chosen/selected/entered)
            var cva2Collection = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var cva2 in cva2Collection)
            {
                if (cva2.IsRequired)
                {
                    bool found = false;
                    //selected checkout attributes
                    foreach (var cva1 in cva1Collection)
                    {
                        if (cva1.Id == cva2.Id)
                        {
                            var cvaValuesStr = ParseValues(selectedAttributes, cva1.Id);
                            foreach (string str1 in cvaValuesStr)
                            {
                                if (!String.IsNullOrEmpty(str1.Trim()))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                    }

                    //if not found
                    if (!found)
                    {
                        var notFoundWarning = string.Format(_localizationService.GetResource("ShoppingCart.SelectAttribute"), cva2.GetLocalized(a => a.Name));

                        warnings.Add(notFoundWarning);
                    }
                }
            }

            return(warnings);
        }
        private void HydrateOption(ICustomerAttributeService customerAttributeService)
        {
            List <CustomerAttributeValue> values = new List <CustomerAttributeValue>();

            foreach (CustomerAttribute a in customerAttributeService.GetAllCustomerAttributes())
            {
                if (a.Name != "Coordinator")
                {
                    continue;
                }

                foreach (var v in a.CustomerAttributeValues.OrderByDescending(x => x.Id))
                {
                    _options.Insert(0, new DropDownOption {
                        Id = v.Id, Name = v.Name
                    });
                }
            }
        }
        public ActionResult List(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSettings))
            {
                return(AccessDeniedView());
            }

            var customerAttributes = _customerAttributeService.GetAllCustomerAttributes();
            var gridModel          = new DataSourceResult
            {
                Data = customerAttributes.Select(x =>
                {
                    var attributeModel = x.ToModel();
                    attributeModel.AttributeControlTypeName = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext);
                    return(attributeModel);
                }),
                Total = customerAttributes.Count()
            };

            return(Json(gridModel));
        }
        /// <summary>
        /// Validates customer attributes
        /// </summary>
        /// <param name="attributesXml">Attributes in XML format</param>
        /// <returns>Warnings</returns>
        public virtual IList <string> GetAttributeWarnings(string attributesXml)
        {
            var warnings = new List <string>();

            //ensure it's our attributes
            var attributes1 = ParseCustomerAttributes(attributesXml);

            //validate required customer attributes (whether they're chosen/selected/entered)
            var attributes2 = _customerAttributeService.GetAllCustomerAttributes();

            foreach (var a2 in attributes2)
            {
                if (!a2.IsRequired)
                {
                    continue;
                }

                var found = false;
                //selected customer attributes
                foreach (var a1 in attributes1)
                {
                    if (a1.Id != a2.Id)
                    {
                        continue;
                    }

                    var valuesStr = ParseValues(attributesXml, a1.Id);

                    found = valuesStr.Any(str1 => !string.IsNullOrEmpty(str1.Trim()));
                }

                if (found)
                {
                    continue;
                }
            }

            return(warnings);
        }
Esempio n. 14
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);
            }
        }
Esempio n. 15
0
        public async Task <string> Handle(GetParseCustomAttributes request, CancellationToken cancellationToken)
        {
            string attributesXml = "";
            var    attributes    = await _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in attributes)
            {
                string controlId = string.Format("customer_attribute_{0}", attribute.Id);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                {
                    var ctrlAttributes = request.Form[controlId];
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, ctrlAttributes);
                    }
                }
                break;

                case AttributeControlType.Checkboxes:
                {
                    var cblAttributes = request.Form[controlId].ToString();
                    if (!String.IsNullOrEmpty(cblAttributes))
                    {
                        foreach (var item in cblAttributes.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (!String.IsNullOrEmpty(item))
                            {
                                attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                              attribute, item);
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //load read-only (already server-side selected) values
                    var attributeValues = attribute.CustomerAttributeValues;
                    foreach (var selectedAttributeId in attributeValues
                             .Where(v => v.IsPreSelected)
                             .Select(v => v.Id)
                             .ToList())
                    {
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, selectedAttributeId);
                    }
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    var ctrlAttributes = request.Form[controlId].ToString();
                    if (!string.IsNullOrEmpty(ctrlAttributes))
                    {
                        var enteredText = ctrlAttributes.Trim();
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, enteredText);
                    }
                    else
                    {
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, "");
                    }
                }
                break;

                case AttributeControlType.Datepicker:
                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.FileUpload:
                //not supported customer attributes
                default:
                    break;
                }
            }
            return(attributesXml);
        }
Esempio n. 16
0
        protected virtual async Task <string> ParseCustomCustomerAttributes(IFormCollection form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            string attributesXml      = "";
            var    customerAttributes = await _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in customerAttributes)
            {
                string controlId = string.Format("customer_attribute_{0}", attribute.Id);
                switch (attribute.AttributeControlType)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                {
                    var ctrlAttributes = form[controlId];
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, ctrlAttributes);
                    }
                }
                break;

                case AttributeControlType.Checkboxes:
                {
                    var cblAttributes = form[controlId];
                    if (!String.IsNullOrEmpty(cblAttributes))
                    {
                        foreach (var item in cblAttributes.ToString().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                        {
                            if (!String.IsNullOrEmpty(item))
                            {
                                attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                              attribute, item);
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //load read-only (already server-side selected) values
                    var attributeValues = attribute.CustomerAttributeValues;
                    foreach (var selectedAttributeId in attributeValues
                             .Where(v => v.IsPreSelected)
                             .Select(v => v.Id)
                             .ToList())
                    {
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, selectedAttributeId);
                    }
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                {
                    var ctrlAttributes = form[controlId];
                    if (!String.IsNullOrEmpty(ctrlAttributes))
                    {
                        string enteredText = ctrlAttributes.ToString().Trim();
                        attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml,
                                                                                      attribute, enteredText);
                    }
                }
                break;

                case AttributeControlType.Datepicker:
                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.FileUpload:
                //not supported customer attributes
                default:
                    break;
                }
            }

            return(attributesXml);
        }
Esempio n. 17
0
 private CustomerAttribute GetRequiredPasswordChangeCustomerAttribute()
 {
     return(_customerAttributeService.GetAllCustomerAttributes()
            .FirstOrDefault(x => x.Name == RequirePasswordChangePluginCustomerAttributeNames.RequiredPasswordChange));
 }
        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);
        }
        public async Task <IList <CustomAttribute> > Handle(GetParseCustomAttributes request, CancellationToken cancellationToken)
        {
            var customAttributes = new List <CustomAttribute>();
            var attributes       = await _customerAttributeService.GetAllCustomerAttributes();

            foreach (var attribute in attributes)
            {
                if (attribute.IsReadOnly)
                {
                    var attrReadOnly = request.CustomerCustomAttribute.FirstOrDefault(x => x.Key == attribute.Id);
                    if (attrReadOnly != null)
                    {
                        customAttributes.Add(attrReadOnly);
                    }

                    continue;
                }
                string controlId = string.Format("customer_attribute_{0}", attribute.Id);
                switch (attribute.AttributeControlTypeId)
                {
                case AttributeControlType.DropdownList:
                case AttributeControlType.RadioList:
                {
                    request.Form.TryGetValue(controlId, out var ctrlAttributes);
                    if (!string.IsNullOrEmpty(ctrlAttributes))
                    {
                        customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,
                                                                                         attribute, ctrlAttributes).ToList();
                    }
                }
                break;

                case AttributeControlType.Checkboxes:
                {
                    request.Form.TryGetValue(controlId, out var cblAttributes);
                    if (!string.IsNullOrEmpty(cblAttributes))
                    {
                        foreach (var item in cblAttributes)
                        {
                            if (!String.IsNullOrEmpty(item))
                            {
                                customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,
                                                                                                 attribute, item).ToList();
                            }
                        }
                    }
                }
                break;

                case AttributeControlType.ReadonlyCheckboxes:
                {
                    //load read-only (already server-side selected) values
                    var attributeValues = attribute.CustomerAttributeValues;
                    foreach (var selectedAttributeId in attributeValues
                             .Where(v => v.IsPreSelected)
                             .Select(v => v.Id)
                             .ToList())
                    {
                        customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,
                                                                                         attribute, selectedAttributeId).ToList();
                    }
                }
                break;

                case AttributeControlType.TextBox:
                case AttributeControlType.MultilineTextbox:
                case AttributeControlType.Hidden:
                {
                    request.Form.TryGetValue(controlId, out var ctrlAttributes);
                    if (!string.IsNullOrEmpty(ctrlAttributes))
                    {
                        var enteredText = ctrlAttributes.ToString().Trim();
                        customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,
                                                                                         attribute, enteredText).ToList();
                    }
                    else
                    {
                        customAttributes = _customerAttributeParser.AddCustomerAttribute(customAttributes,
                                                                                         attribute, "").ToList();
                    }
                }
                break;

                case AttributeControlType.Datepicker:
                case AttributeControlType.ColorSquares:
                case AttributeControlType.ImageSquares:
                case AttributeControlType.FileUpload:
                //not supported customer attributes
                default:
                    break;
                }
            }
            return(customAttributes);
        }
Esempio n. 21
0
 /// <summary>
 /// Gets all customer attributes
 /// </summary>
 /// <returns>Customer attributes</returns>
 public IList <CustomerAttribute> GetAllCustomerAttributes()
 {
     return(_customerAttributeService.GetAllCustomerAttributes());
 }