Beispiel #1
0
        public void DeleteAttributeValue(CustomerInformationProductAttributeValue attributeValue)
        {
            if (attributeValue == null)
            {
                throw new ArgumentNullException("attribute value");
            }

            _attributeValueRepository.Delete(attributeValue);
        }
Beispiel #2
0
        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);
            }
        }