public void DeleteAttribute(CustomerInformationProductAttribute attribute) { if (attribute == null) { throw new ArgumentNullException("attribute"); } _attributesRepository.Delete(attribute); }
public static CustomerInformationAttributeModel ToModel(this CustomerInformationProductAttribute attribute, string alias, ILocalizationService localizationService, IWorkContext _workContext) { var model = new CustomerInformationAttributeModel(); model.Id = attribute.Id; model.Alias = alias; model.DisplayOrder = attribute.DisplayOrder; model.IncludeEmptyValuesInSearchResults = attribute.IncludeEmptyValuesInSearchResults; model.IsRequired = attribute.IsRequired; model.ProductAddControlTypeId = attribute.ProductAddControlTypeId; model.ProductAddControlType = attribute.ProductAddControlType; model.ProductAddControlTypeString = attribute.ProductAddControlType.GetLocalizedEnum(localizationService, _workContext); model.ProductSearchControlType = attribute.ProductSearchControlType; model.ProductSearchControlTypeId = attribute.ProductSearchControlTypeId; model.ProductSearchControlTypeString = attribute.ProductSearchControlType.GetLocalizedEnum(localizationService, _workContext); return(model); }
public CustomerInformationProductAttribute FillValues(string fieldName) { var attribute = _attributesRepository.Table.Where(x => x.CustomerFieldName == fieldName).FirstOrDefault(); if (attribute == null) { CustomerInformationProductAttribute newAttribute = null; switch (fieldName) { case "Gender": { newAttribute = new CustomerInformationProductAttribute() { CustomerFieldName = "Gender", DisplayOrder = 0, IncludeEmptyValuesInSearchResults = false, IsRequired = false, ProductAddControlTypeId = (int)CustomerInformationProductAddControlType.CheckBoxes, ProductSearchControlTypeId = (int)CustomerInformationProductSearchControlType.Gender, }; _attributesRepository.Insert(newAttribute); var value = new CustomerInformationProductAttributeValue() { CustomerInformationProductAttributeId = newAttribute.Id, ReferenceValueInt = 0, ValueString = "Ж" }; _attributeValueRepository.Insert(value); value = new CustomerInformationProductAttributeValue() { CustomerInformationProductAttributeId = newAttribute.Id, ReferenceValueInt = 1, ValueString = "М" }; _attributeValueRepository.Insert(value); break; } case "Income": { newAttribute = new CustomerInformationProductAttribute() { CustomerFieldName = "Income", DisplayOrder = 0, IncludeEmptyValuesInSearchResults = false, IsRequired = false, ProductAddControlTypeId = (int)CustomerInformationProductAddControlType.NumberTextBoxValue, ProductSearchControlTypeId = (int)CustomerInformationProductSearchControlType.NumberToddlerMore, }; _attributesRepository.Insert(newAttribute); break; } case "BirthdayDate": { newAttribute = new CustomerInformationProductAttribute() { CustomerFieldName = "BirthdayDate", DisplayOrder = 0, IncludeEmptyValuesInSearchResults = false, IsRequired = false, ProductAddControlTypeId = (int)CustomerInformationProductAddControlType.NumberTextBoxRange, ProductSearchControlTypeId = (int)CustomerInformationProductSearchControlType.NumberTextBoxExact, }; _attributesRepository.Insert(newAttribute); break; } case "CityId": { newAttribute = new CustomerInformationProductAttribute() { CustomerFieldName = "CityId", DisplayOrder = 0, IncludeEmptyValuesInSearchResults = false, IsRequired = false, ProductAddControlTypeId = (int)CustomerInformationProductAddControlType.ReferenceValue, ProductSearchControlTypeId = (int)CustomerInformationProductSearchControlType.DropDownList, }; _attributesRepository.Insert(newAttribute); var cities = _cityService.GetAllCities(); foreach (var city in cities) { var value = new CustomerInformationProductAttributeValue() { CustomerInformationProductAttributeId = newAttribute.Id, ReferenceValueInt = city.Id }; _attributeValueRepository.Insert(value); } break; } } return(newAttribute); } else { switch (attribute.CustomerFieldName) { case "CityId": { var values = GetValuesByAttributeId(attribute.Id); var cities = _cityService.GetAllCities(); foreach (var city in cities) { if (values.Where(x => x.ReferenceValueInt == city.Id).FirstOrDefault() == null) { var value = new CustomerInformationProductAttributeValue() { CustomerInformationProductAttributeId = attribute.Id, ReferenceValueInt = city.Id }; _attributeValueRepository.Insert(value); } } break; } } return(attribute); } }