List Deparments programatically

Posted by Community Admin on 05-Aug-2018 12:35

List Deparments programatically

All Replies

Posted by Community Admin on 18-Nov-2011 00:00

I need to build my own navigation widget for the Departments of a store.

But I can't find any documentation on how to grab and list Departments. Only to simple crud operations. I suppose this is done the same way as other taxons, but I can't find any examples of that as well.

Anyone?

OC

Posted by Community Admin on 18-Nov-2011 00:00

You can use the TaxonomyManager to get all of the Departments.

Something like:

var departmentsTaxonomy = TaxonomyManager.GetManager().GetTaxonomy(TaxonomyManager.DepartmentsTaxonomyId);

Will get you the departments taxonomy. After that you can access each Department by iterating over the "Taxa" property of "departmentsTaxonomy".


Regards,
Thomas

Posted by Community Admin on 22-Nov-2011 00:00

Thanks Thomas,

I ended up using this code, witch works great:

    TaxonomyManager tm = TaxonomyManager.GetManager();
    var depatments = tm.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == "Departments").SingleOrDefault();
 
   var subGroup = depatments.Taxa.Where(t => t.Title == itm.ToolTip).SingleOrDefault();
 
        if(subGroup!= null)
            foreach (HierarchicalTaxon t in subGroup.Taxonomy.Taxa.Where(a => a.Parent == subGroup))
            
                RadMenuItem newItm = new RadMenuItem(t.Title);
                newItm.CssClass = itm.ToolTip + "MenuItem";
                itm.Items.Add(newItm);
                 
            


BUT: How can I get the subgroup Taxas sorted?

Thanks for any input!

OC

Posted by Community Admin on 24-Nov-2011 00:00

Hi Ole,

You can cast your first result to HierarchicalTaxon and then simply use the Subtaxa property of HierarchicalTaxon and use the OrderBy method of LINQ:

var subGroup = depatments.Taxa.Where(t => t.Title == "Title").SingleOrDefault() as HierarchicalTaxon;
foreach (HierarchicalTaxon t in subGroup.Subtaxa.OrderBy(t => t.Title))
                     

Greetings,
Lubomir Velkov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed