Created
August 12, 2013 09:00
-
-
Save sitefinitySDK/6209306 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using Telerik.Sitefinity.Taxonomies; | |
using Telerik.Sitefinity.Taxonomies.Model; | |
namespace Telerik.Sitefinity.Documentation.CodeSnippets.DevGuide.SitefinityEssentials.Taxonomies.HierarchicalTaxonomies.HierarchicalTaxonomyAPI | |
{ | |
public partial class HierarchicalTaxonomyAPI | |
{ | |
public void CreateHierarchicalTaxonomyAndTaxon() | |
{ | |
var manager = TaxonomyManager.GetManager(); | |
manager.Provider.SuppressSecurityChecks = true; | |
var categoriestaxonomy = manager.GetTaxonomy<HierarchicalTaxonomy>(TaxonomyManager.CategoriesTaxonomyId); | |
//Create a new hierarhical taxonomy using the TaxonomyManager class | |
//Create a new taxon and add it to the taxonomy - Language Groups | |
var rootTaxonCateg = manager.CreateTaxon<HierarchicalTaxon>(); | |
rootTaxonCateg.Title = "Language Groups"; | |
rootTaxonCateg.Name = "Language Groups"; | |
rootTaxonCateg.Description = "Language groups description"; | |
rootTaxonCateg.Taxonomy = categoriestaxonomy; | |
categoriestaxonomy.Taxa.Add(rootTaxonCateg); | |
//Create two sub-taxa and add them to the Language Groups taxon. | |
//1 | |
var taxonSubCateg = manager.CreateTaxon<HierarchicalTaxon>(); | |
taxonSubCateg.Title = "Languages"; | |
taxonSubCateg.Name = "Languages"; | |
taxonSubCateg.Description = "Languages description"; | |
taxonSubCateg.Parent = rootTaxonCateg; | |
taxonSubCateg.Taxonomy = categoriestaxonomy; | |
rootTaxonCateg.Subtaxa.Add(taxonSubCateg); | |
//2 | |
var taxonChildSubCateg = manager.CreateTaxon<HierarchicalTaxon>(); | |
taxonChildSubCateg.Title = "Dialects"; | |
taxonChildSubCateg.Name = "Dialects"; | |
taxonChildSubCateg.Description = "Dialects description"; | |
taxonChildSubCateg.Parent = taxonSubCateg; | |
taxonChildSubCateg.Taxonomy = categoriestaxonomy; | |
taxonSubCateg.Subtaxa.Add(taxonChildSubCateg); | |
//Save all changes done up to now. | |
manager.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment