Add Category to Event
I'm creating a widget that allows users to create Events from the frontend, as I saw no other way to accomplish this out of the box. The Events are creating successfully and now I'm trying to add Categories to them to allow me to filter their display later. I'm not sure exactly how to accomplish adding the categories to the new event programmatically.
I saw the following code sample in the API documentation, but I don't believe Events have a Tags or Categories property.
var taxManager = TaxonomyManager.GetManager();
var taxon = taxManager.GetTaxa<FlatTaxon>().Where(t => t.Name ==
"Book"
).Single();
var contentManager = ContentManager.GetManager();
var allContent = contentManager.GetContent();
foreach
(var content
in
allContent)
content.Organizer.AddTaxa(
"Tags"
, taxon);
contentManager.SaveChanges();
How would I go about accomplishing this using an Event object?
Thanks
Hi Geoff,
Below is the code that you can use to add a category called "mycategory" to content items
var taxManager = TaxonomyManager.GetManager();
var taxon = taxManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name ==
"mycategory"
).Single();
var contentManager = ContentManager.GetManager();
var allContent = contentManager.GetContent();
foreach
(var content
in
allContent)
content.Organizer.AddTaxa(
"Category"
, taxon.Id);
contentManager.SaveChanges();
That took care of it. I appreciate the fast response.
hi,
Is their any way to get all the categories of "Events" to bind in to a drop down ?
Hello Rakesh,
Taxons are set per item, so you need to get the events and then all event items where GetValue("Category") is not an empty string.
Best wishes,
Ivan Dimitrov
the Telerik team