Add Category to Event

Posted by Community Admin on 05-Aug-2018 21:34

Add Category to Event

All Replies

Posted by Community Admin on 03-Mar-2011 00:00

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

Posted by Community Admin on 04-Mar-2011 00:00

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();


Greetings,
Ivan Dimitrov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!

Posted by Community Admin on 04-Mar-2011 00:00

That took care of it.  I appreciate the fast response.

Posted by Community Admin on 12-Oct-2011 00:00

hi,

Is their any way to get all the categories of "Events" to bind in to a drop down ?

Posted by Community Admin on 12-Oct-2011 00:00

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

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

This thread is closed