예제 #1
0
        private CategoryAttributeValue GetCategoryAttributeValuesForMultiselect(CategoryAttribute attribute, AttributeValueModel attributeValue)
        {
            var selectedOptions = new Collection<CategoryAttributeOption>();
            for (var i = 0; i < attribute.Options.Count; i++)
                if (bool.Parse(attributeValue.Values[i]))
                    selectedOptions.Add(attribute.Options.ElementAt(i));

            return selectedOptions.Any() ? new CategoryAttributeValue { Attribute = attribute, SelectedOptions = selectedOptions } : null;
        }
예제 #2
0
        public static AttributeValueModel[] GetCategoryAttributeValueModel(IEnumerable<CategoryAttributeValue> attributeValues, bool forExpert = false)
        {
            List<AttributeValueModel> results = new List<AttributeValueModel>();
            foreach(var value in attributeValues)
            {
                
                var selectedValues = new List<string>();

                if (value.Attribute.Type == CategoryAttributeType.MultiSelect || forExpert)
                {
                    foreach (var option in value.Attribute.Options)
                    {
                        var isSelected = value.SelectedOptions.Contains(option);
                        selectedValues.Add(isSelected.ToString());
                    }
                }

                var model = new AttributeValueModel 
                    {
                        AttributeId = value.Attribute.Id,
                        Value = value.Attribute.Type == CategoryAttributeType.SingleSelect && !forExpert ? value.SelectedOptions.Single().Id.ToString() : value.Value, 
                        Values = selectedValues.ToArray() 
                    };
                
                results.Add(model);
            }
            return results.ToArray();
        }
예제 #3
0
        private ActionResult GetChildCategoryAttributesActionResult(AttributeValueModel[] attributeValues, int attributeId)
        {
            var helper = new CategoryAttributeHelper();
            var categoryAttributeValues = helper.GetCategoryAttributeValues(attributeValues.Where(cv => cv.AttributeId == attributeId), true);
            var allSubAttributes = categoryAttributeValues.SelectMany(cav => cav.Attribute.ChildAttributes);
            var selectedSubAttributes = allSubAttributes.Where(sa => categoryAttributeValues.Any(cav => cav.SelectedOptions.Intersect(sa.ParentOptions).Any()));

            var attributes = selectedSubAttributes.Where(ca => ca.Type == CategoryAttributeType.MultiSelect || ca.Type == CategoryAttributeType.SingleSelect).ToList();

            var model = new ExpertCategoryAttributesModel
            {
                CategoryAttributes = attributes,
                CategoryAttributeValues = attributeValues
            };

            return PartialView(MVC.Account.Views._ExpertCategoryAttributes, model);
        }