More in this section

Forums / General Discussions / Filter Events by category

Filter Events by category

9 posts, 0 answered
  1. mario
    mario avatar
    23 posts
    Registered:
    08 Aug 2011
    14 Sep 2011
    Link to this post
    Hello Team,

    I need to filter some evnts by category, using the fluent API
    something like:

    List<Event> allEvents = App.WorkWith().Events().Get()
                                        .Where(t => t.Status == ContentLifecycleStatus.Live)                                   
                                        .Where(t => t.Category.Contains("IMPORTANT"))   // <<----- like this
                                        .ToList();


    there is some way to get this?


    thanks
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    16 Sep 2011
    Link to this post
    Hi Mario,

    Yes, it's possible to filter by the Categories field, you will need to use the extension method GetValue for that purpose. For example:
    var importantCategoryId = new Guid("your category ID");
    List<Event> allEvents = App.WorkWith().Events().Get()
                                        .Where(t => t.Status == ContentLifecycleStatus.Live)                                  
                                        .Where(t => t.GetValue<TrackedList<Guid>>("Category").Contains( importantCategoryId ))
                                        .ToList();
    The GetValue() method will return a TrackedList of the category IDs assigned to that content item, so you'll need to check for the particular ID of that category.

    Please note you'll need to add a reference to Telerik.Sitefinity.Model


    All the best,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. mario
    mario avatar
    23 posts
    Registered:
    08 Aug 2011
    20 Sep 2011
    Link to this post
    Thanks Boyan!

    It worked like a charm! :D




    -Mario Araya-
  4. Kevin
    Kevin avatar
    38 posts
    Registered:
    06 Sep 2011
    03 Oct 2011
    Link to this post
    I'm trying to implement this solution, but I'm feeling quite dense here... how do I obtain the GUID for the category?
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    03 Oct 2011
    Link to this post
    Hi Kevin,

    You can either look it up in the database table dbo_sf_taxa or get the taxonomy by its name using the Taxonomies API, and then get the ID of that taxonomy and pass it along to the provide sample code

    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. martin
    martin avatar
    36 posts
    Registered:
    30 Nov 2008
    13 Dec 2011
    Link to this post

    hi,

    Is there a way to filter by tags.

    List<Event> allEvents = App.WorkWith().Events().Get()
    .Where(t => t.Status == ContentLifecycleStatus.Live)
    .Where(t => t.GetValue<TrackedList<Guid>>("Tag").Contains( importantTagId ))
    .ToList();
  7. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    30 Oct 2017
    13 Dec 2011
    Link to this post
    Hi Martin,

    Absolutely, however, the name of the metafield is Tags, not Tag, this would probably throw an exception. Please try using t.GetValue<TrackedList<Guid>>("Tags").Contains( importantTagId ) instead.


    Kind regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Justin
    Justin avatar
    5 posts
    Registered:
    30 Sep 2011
    23 Mar 2012
    Link to this post
    I'm beating my head against the wall on this one!  
    I need to get the title, content, and category out of a ListItem, but I cannot figure out how to get the category string value out of a list item, since it is not exposed as a property.
    See the code below.
    
    List<IFrequentlyAskedQuestion> frequentlyAskedQuestions = new List<IFrequentlyAskedQuestion>();
    List<ListItem> listItems = App.WorkWith().ListItems().Where(l => l.Parent.Title == "Frequently Asked Questions").Get().ToList();

    foreach (var item in listItems)
    {
    frequentlyAskedQuestions.Add(new FrequentlyAskedQuestion()  {Category = item.GetValue<TrackedList<Guid>>("Category").ToString(), Question = item.Title, Answer = item.Content});
     }

    return frequentlyAskedQuestions.OrderBy(x => x.Category).ThenBy(x => x.Question).ToList();
  9. Justin
    Justin avatar
    5 posts
    Registered:
    30 Sep 2011
    23 Mar 2012
    Link to this post
    I'm beating my head against the wall on this one!  
    I need to get the title, content, and category out of a ListItem, but I cannot figure out how to get the category string value out of a list item, since it is not exposed as a property.
    See the code below.
    
    List<IFrequentlyAskedQuestion> frequentlyAskedQuestions = new List<IFrequentlyAskedQuestion>();
    List<ListItem> listItems = App.WorkWith().ListItems().Where(l => l.Parent.Title == "Frequently Asked Questions").Get().ToList();

    foreach (var item in listItems)
    {
    frequentlyAskedQuestions.Add(new FrequentlyAskedQuestion()  {Category = item.GetValue<TrackedList<Guid>>("Category").ToString(), Question = item.Title, Answer = item.Content});
     }

    return frequentlyAskedQuestions.OrderBy(x => x.Category).ThenBy(x => x.Question).ToList();
9 posts, 0 answered