+1-888-365-2779
Try Now
More in this section

Forums / Sitefinity SDK / Add Category to Event

Add Category to Event

5 posts, 1 answered
  1. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    03 Mar 2011
    Link to this post
    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
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    04 Mar 2011
    Link to this post
    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!
    Answered
  3. Geoff
    Geoff avatar
    89 posts
    Registered:
    02 Mar 2011
    04 Mar 2011
    Link to this post
    That took care of it.  I appreciate the fast response.
  4. Rakesh
    Rakesh avatar
    72 posts
    Registered:
    11 Jan 2011
    12 Oct 2011
    Link to this post
    hi,

    Is their any way to get all the categories of "Events" to bind in to a drop down ?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Oct 2011
    Link to this post
    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 >>

5 posts, 1 answered