List Deparments programatically
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
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
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);
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))