public virtual async Task <IEnumerable <ContactAttributeModel> > PrepareContactAttributeListModel() { var contactAttributes = await _contactAttributeService.GetAllContactAttributes(_workContext.CurrentCustomer.StaffStoreId, ignorAcl : true); return(contactAttributes.Select(x => { var attributeModel = x.ToModel(); attributeModel.AttributeControlTypeName = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext); return attributeModel; })); }
public virtual IEnumerable <ContactAttributeModel> PrepareContactAttributeListModel() { var contactAttributes = _contactAttributeService.GetAllContactAttributes(); return(contactAttributes.Select(x => { var attributeModel = x.ToModel(); attributeModel.AttributeControlTypeName = x.AttributeControlType.GetLocalizedEnum(_localizationService, _workContext); return attributeModel; })); }
public virtual async Task <IActionResult> ContactAttributeChange(IFormCollection form, [FromServices] IContactAttributeParser contactAttributeParser) { var attributeXml = await _commonViewModelService.ParseContactAttributes(form); var enabledAttributeIds = new List <string>(); var disabledAttributeIds = new List <string>(); var attributes = await _contactAttributeService.GetAllContactAttributes(_storeContext.CurrentStore.Id); foreach (var attribute in attributes) { var conditionMet = await contactAttributeParser.IsConditionMet(attribute, attributeXml); if (conditionMet.HasValue) { if (conditionMet.Value) { enabledAttributeIds.Add(attribute.Id); } else { disabledAttributeIds.Add(attribute.Id); } } } return(Json(new { enabledattributeids = enabledAttributeIds.ToArray(), disabledattributeids = disabledAttributeIds.ToArray() })); }
protected virtual void PrepareConditionAttributes(ContactAttributeModel model, ContactAttribute contactAttribute) { if (model == null) { throw new ArgumentNullException("model"); } //currenty any contact attribute can have condition. model.ConditionAllowed = true; if (contactAttribute == null) { return; } var selectedAttribute = _contactAttributeParser.ParseContactAttributes(contactAttribute.ConditionAttributeXml).FirstOrDefault(); var selectedValues = _contactAttributeParser.ParseContactAttributeValues(contactAttribute.ConditionAttributeXml); model.ConditionModel = new ConditionModel() { EnableCondition = !string.IsNullOrEmpty(contactAttribute.ConditionAttributeXml), SelectedAttributeId = selectedAttribute != null ? selectedAttribute.Id : "", ConditionAttributes = _contactAttributeService.GetAllContactAttributes() //ignore this attribute and non-combinable attributes .Where(x => x.Id != contactAttribute.Id && x.CanBeUsedAsCondition()) .Select(x => new AttributeConditionModel() { Id = x.Id, Name = x.Name, AttributeControlType = x.AttributeControlType, Values = x.ContactAttributeValues .Select(v => new SelectListItem() { Text = v.Name, Value = v.Id.ToString(), Selected = selectedAttribute != null && selectedAttribute.Id == x.Id && selectedValues.Any(sv => sv.Id == v.Id) }).ToList() }).ToList() }; }
private async Task <IList <ContactUsModel.ContactAttributeModel> > PrepareContactAttributeModel(ContactUsCommand request) { var model = new List <ContactUsModel.ContactAttributeModel>(); var contactAttributes = await _contactAttributeService.GetAllContactAttributes(request.Store.Id); foreach (var attribute in contactAttributes) { var attributeModel = new ContactUsModel.ContactAttributeModel { Id = attribute.Id, Name = attribute.GetLocalized(x => x.Name, request.Language.Id), TextPrompt = attribute.GetLocalized(x => x.TextPrompt, request.Language.Id), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, DefaultValue = attribute.DefaultValue }; if (!string.IsNullOrEmpty(attribute.ValidationFileAllowedExtensions)) { attributeModel.AllowedFileExtensions = attribute.ValidationFileAllowedExtensions .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } if (attribute.ShouldHaveValues()) { //values var attributeValues = attribute.ContactAttributeValues; foreach (var attributeValue in attributeValues) { var attributeValueModel = new ContactUsModel.ContactAttributeValueModel { Id = attributeValue.Id, Name = attributeValue.GetLocalized(x => x.Name, request.Language.Id), ColorSquaresRgb = attributeValue.ColorSquaresRgb, IsPreSelected = attributeValue.IsPreSelected, DisplayOrder = attributeValue.DisplayOrder, }; attributeModel.Values.Add(attributeValueModel); } } model.Add(attributeModel); } return(model); }
private async Task <IList <ContactUsModel.ContactAttributeModel> > PrepareContactAttributeModel(ContactUsCommand request) { var model = new List <ContactUsModel.ContactAttributeModel>(); var contactAttributes = await _contactAttributeService.GetAllContactAttributes(request.Store.Id); foreach (var attribute in contactAttributes) { var attributeModel = new ContactUsModel.ContactAttributeModel { Id = attribute.Id, Name = attribute.GetLocalized(x => x.Name, request.Language.Id), TextPrompt = attribute.GetLocalized(x => x.TextPrompt, request.Language.Id), IsRequired = attribute.IsRequired, AttributeControlType = attribute.AttributeControlType, DefaultValue = request.Form?[$"contact_attribute_{attribute.Id}"] ?? attribute.DefaultValue, }; if (attribute.AttributeControlType == Domain.Catalog.AttributeControlType.Datepicker) { int.TryParse(request.Form?[$"contact_attribute_{attribute.Id}_day"], out var selectedDay); if (selectedDay > 0) { attributeModel.SelectedDay = selectedDay; } int.TryParse(request.Form?[$"contact_attribute_{attribute.Id}_month"], out var selectedMonth); if (selectedMonth > 0) { attributeModel.SelectedMonth = selectedMonth; } int.TryParse(request.Form?[$"contact_attribute_{attribute.Id}_year"], out var selectedYear); if (selectedYear > 0) { attributeModel.SelectedYear = selectedYear; } } if (!string.IsNullOrEmpty(attribute.ValidationFileAllowedExtensions)) { attributeModel.AllowedFileExtensions = attribute.ValidationFileAllowedExtensions .Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList(); } if (attribute.ShouldHaveValues()) { //values var attributeValues = attribute.ContactAttributeValues; foreach (var attributeValue in attributeValues) { var preSelected = request.Form?[$"contact_attribute_{attribute.Id}"].ToString(); var attributeValueModel = new ContactUsModel.ContactAttributeValueModel { Id = attributeValue.Id, Name = attributeValue.GetLocalized(x => x.Name, request.Language.Id), ColorSquaresRgb = attributeValue.ColorSquaresRgb, IsPreSelected = string.IsNullOrEmpty(preSelected) ? attributeValue.IsPreSelected : (preSelected.Contains(attributeValue.Id)), DisplayOrder = attributeValue.DisplayOrder, }; attributeModel.Values.Add(attributeValueModel); } } model.Add(attributeModel); } return(model); }