Add Category to Event - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Add Category to Event

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


    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!
  • 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
    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>