Filter Events by category

Posted by Community Admin on 03-Aug-2018 23:20

Filter Events by category

All Replies

Posted by Community Admin on 14-Sep-2011 00:00

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

Posted by Community Admin on 16-Sep-2011 00:00

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

Posted by Community Admin on 20-Sep-2011 00:00

Thanks Boyan!

It worked like a charm! :D




-Mario Araya-

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

I'm trying to implement this solution, but I'm feeling quite dense here... how do I obtain the GUID for the category?

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

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

Posted by Community Admin on 13-Dec-2011 00:00

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

Posted by Community Admin on 13-Dec-2011 00:00

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

Posted by Community Admin on 23-Mar-2012 00:00

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

Posted by Community Admin on 23-Mar-2012 00:00

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

This thread is closed