Пример #1
0
            public static void CreateHierarchicalTaxonomyAndTaxon()
            {
                //gets an instance of the taxonomy manager
                TaxonomyManager manager = TaxonomyManager.GetManager();

                //creates hierarchical taxonomy - Language family
                var taxonomy = manager.CreateTaxonomy <HierarchicalTaxonomy>();

                taxonomy.Title     = "Language family";
                taxonomy.Name      = "Language family";
                taxonomy.TaxonName = "Language family";

                //creates a new taxon and adds it to the taxonomy - Language Groups
                var rootTaxonCateg = manager.CreateTaxon <HierarchicalTaxon>();

                rootTaxonCateg.Title       = "Language Groups";
                rootTaxonCateg.Name        = "Language Groups";
                rootTaxonCateg.UrlName     = new Lstring(Regex.Replace("Language Groups", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                rootTaxonCateg.Description = "Language groups description";
                rootTaxonCateg.Taxonomy    = taxonomy;
                taxonomy.Taxa.Add(rootTaxonCateg);

                //creates two sub-taxa and adds them to the Language Groups taxon.
                //1
                var taxonSubCateg = manager.CreateTaxon <HierarchicalTaxon>();

                taxonSubCateg.Title       = "Languages";
                taxonSubCateg.Name        = "Languages";
                taxonSubCateg.UrlName     = new Lstring(Regex.Replace("Languages", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                taxonSubCateg.Description = "Languages description";
                taxonSubCateg.Parent      = rootTaxonCateg;
                taxonSubCateg.Taxonomy    = taxonomy;
                rootTaxonCateg.Subtaxa.Add(taxonSubCateg);

                //2
                var taxonChildSubCateg = manager.CreateTaxon <HierarchicalTaxon>();

                taxonChildSubCateg.Title       = "Dialects";
                taxonChildSubCateg.Name        = "Dialects";
                taxonChildSubCateg.UrlName     = new Lstring(Regex.Replace("Dialects", @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-").ToLower());
                taxonChildSubCateg.Description = "Dialects description";
                taxonChildSubCateg.Parent      = taxonSubCateg;
                taxonChildSubCateg.Taxonomy    = taxonomy;
                taxonSubCateg.Subtaxa.Add(taxonChildSubCateg);

                //Save all changes done up to now.
                manager.SaveChanges();
            }