Esempio n. 1
0
        public static void AddCatetories(string tags, CategoryTag root)
        {
            if (String.IsNullOrEmpty(tags) || root == null)
            {
                return;
            }

            var parentCategory = root;

            while (!String.IsNullOrEmpty(tags))
            {
                var firstTag         = CategoryTag.GetFirstCategory(tags);
                var hasSubCategoryVm = false;

                if (firstTag == parentCategory.Name)
                {
                    tags = CategoryTag.GetSubTags(tags);
                    continue;
                }

                CategoryTag category = null;

                foreach (var sub in parentCategory.SubCategories)
                {
                    if (sub.Name == firstTag)
                    {
                        category         = sub;
                        hasSubCategoryVm = true;
                        break;
                    }
                }
                if (hasSubCategoryVm == false)
                {
                    category = new CategoryTag(firstTag, parentCategory);
                    parentCategory.SubCategories.Add(category);
                }

                tags           = CategoryTag.GetSubTags(tags);
                parentCategory = category;
            }
        }
Esempio n. 2
0
        public CategoryTag(string tag, CategoryTag parent = null)
        {
            if (String.IsNullOrWhiteSpace(tag) || String.IsNullOrEmpty(tag.Trim(SPLITTERS)))
            {
                tag = CategoryOthers;
            }
            _categoryName = tag.Trim(SPLITTERS);
            _name         = GetLastCategory(tag);

            SubCategories = new List <CategoryTag>();
            Parent        = parent;

            if (parent != null)
            {
                while (parent != null)
                {
                    Root = parent; parent = parent.Parent;
                }
            }
            else // trace up to the root
            {
                Root = null;
            }
        }