TaxonomyManager manager = TaxonomyManager.GetManager();
var pManager = CatalogManager.GetManager();
var myCategoryId = manager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name ==
"TT"
).Single().Id;
var productList = pManager.GetProducts().ToList();
foreach
(var product
in
productList)
var catlist = product.GetValue<TrackedList<Guid>>(
"Department"
);
catlist.Add(myCategoryId);
product.SetValue(
, catlist);
pManager.SaveChanges();
NewsItem item = manager.CreateNewsItem();
...
if (item.DoesFieldExist('Department")) // if the field exists.
if (!item.Organizer.TaxonExists("Department", valueID))
item.Organizer.AddTaxa('Department", valueID); //Add taxonomy
//First get the manager which operates with Taxonomies
//Get the manager corresponding to the Content type you'll be operating with
CatalogManagerpManager = CatalogManager.GetManager();
//Get the ID of a singe instance (HierarchicalTaxon) of type Hierarchicaltaxonomy
//(This can be Categories, Departments, or any custom HierarchicalTaxonomy)
//Get a list of content items of the desired Content type
//For each of the content items in the above constructed list
//Get all the IDs of the HierarchicalTaxons in the HierarchicalTaxonomy "Departments"
// which is stored in the "Department metafield of this content item"
//modify the list as per your requirements
//assign the modified list to the "Department metafield of this content item
//this is equivalent to adding a new Department to a product through the UI
//Commit the changes
NewsManager nManager = NewsManager.GetManager();
"MyNewsCategory"
var newsList = nManager.GetNewsItems().ToList();
(var newsItem
newsList)
var catlist = newsItem.GetValue<TrackedList<Guid>>(
"Category"
newsItem.SetValue(
nManager.SaveChanges();
Hi Boyan,
Thanks for your information, perhaps I didn't explain well and I used taxonomies as a bad example. It's not Taxonomies but "Custom Fields". Now, I know how add "Custom Fields" throughout Sitefinity Back-End (http://www.sitefinity.com/documentation/user-guide/creating-and-uploading-content/adding-custom-fields-to-content-items/creating-a-new-custom-field.aspx) but how can I do the same process using API's? Is there any way to do that?
I used taxonomies at the beginning since they could also added as “Custom Fields”.
Thanks again, sorry for confusion and hope I clarify my question. Regards, Nathalia.
//get an instance of MetadataManager and create a MetaType for Subscriber
var metaManager = Telerik.Sitefinity.Data.Metadata.MetadataManager.GetManager();
metaManager.CreateMetaType(
typeof
(Subscriber));
metaManager.SaveChanges();
//create the new MetaField for the MetaType Subscriber, that will persist the "Organization" value
App.WorkWith().DynamicData().Type(
(Subscriber)).Field().CreateNew(
"Gender"
,
(String)).SaveChanges(
true
var newslettersManager = NewslettersManager.GetManager(
this
.ProviderName);
Subscriber subscriber = newslettersManager.GetSubscribers().Where(s => s.Email == email).SingleOrDefault();
if
(subscriber !=
null
&& !String.IsNullOrEmpty(Gender.Text))
subscriber.SetValue(
, Gender.Text);
newslettersManager.SaveChanges();