Ejemplo n.º 1
0
        public List <TermTaxonomyView> GenerateNestedList(TermTaxonomyView parent, int taxonomy, string companyId)
        {
            var all = new List <TermTaxonomyView>();

            if (parent == null)
            {
                return(all);
            }

            //parent.Disabled = true;

            all.Add(parent);
            var tempNestedList = (from tx in db.TermTaxonomy
                                  join te in db.Term
                                  on tx.TermId equals te.Id
                                  where tx.Parent == parent.TermId
                                  select new TermTaxonomyView
            {
                TermId = te.Id,
                Name = te.Name,
                Parent = tx.Parent,
                Disabled = te.Disabled.HasValue && te.Disabled.Value
            }).ToList();

            if (tempNestedList != null && tempNestedList.Any())
            {
                foreach (var item in tempNestedList)
                {
                    all.Add(item);

                    List <TermTaxonomyView> childTerms = (from tx in db.TermTaxonomy
                                                          join te in db.Term
                                                          on tx.TermId equals te.Id
                                                          where tx.Parent == item.TermId
                                                          select new TermTaxonomyView
                    {
                        TermId = te.Id,
                        Name = te.Name,
                        Parent = tx.Parent,
                        Disabled = te.Disabled.HasValue && te.Disabled.Value
                    }).ToList();
                    if (childTerms != null && childTerms.Any())
                    {
                        AddChildTerms(all, childTerms);
                    }
                }
            }


            return(all);
        }
Ejemplo n.º 2
0
        private void AddChildTerms(TermTaxonomyView childTerm, StringBuilder builder, List <TermTaxonomyView> terms)
        {
            builder.Append(OPEN_LIST_TAG);
            List <TermTaxonomyView> childTerms = (from a in terms where a.Parent == childTerm.TermId select a).ToList();

            foreach (TermTaxonomyView term in childTerms)
            {
                //builder.Append(string.Format(OPEN_LIST_ITEM_TAG, term.Name, term.Id));
                builder.Append(string.Format(OPEN_LIST_ITEM_TAG, term.Name, term.TermId, term.NoDragClass ? 1 : 0, term.NoChildrenClass ? 1 : 0
                                             , !string.IsNullOrWhiteSpace(term.Color) ? term.Color : "#fafafa"
                                             , term.NoChildrenClass ? "dd-nochildren" : string.Empty
                                             , term.NoDragClass ? "dd-nodrag" : string.Empty));
                builder.Append(string.Format(LIST_ITEM_CONTENT, term.Name, !string.IsNullOrWhiteSpace(term.Color) ? term.Color : "#fafafa"));
                //builder.Append(string.Format(EDIT_BUTTON, term.Name, term.Term_Id, term.DoDragClass ? 1 : 0, term.NoChildrenClass ? 1 : 0));
                List <TermTaxonomyView> subChilds = (from a in terms where a.Parent == term.TermId select a).ToList();
                if (subChilds.Count > 0)
                {
                    AddChildTerms(term, builder, terms);
                }
                builder.Append(CLOSE_LIST_ITEM_TAG);
            }
            builder.Append(CLOSE_LIST_TAG);
        }