private void AddAttribute(string enteredText, CustomerAttribute attribute, ref string attributesXml) { if (!string.IsNullOrWhiteSpace(enteredText)) { attributesXml = _customerAttributeParser.AddCustomerAttribute(attributesXml, attribute, enteredText); } }
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); }
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); }
/// <summary> /// Adds an attribute /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <param name="ca">Customer attribute</param> /// <param name="value">Value</param> /// <returns>Attributes</returns> string AddCustomerAttribute(string attributesXml, CustomerAttribute ca, string value) { return(_customerAttributeParser.AddCustomerAttribute(attributesXml, ca, value)); }
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); }