Filter Events by category
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
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();
Thanks Boyan!
It worked like a charm! :D
-Mario Araya-
I'm trying to implement this solution, but I'm feeling quite dense here... how do I obtain the GUID for the category?
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
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();
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
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();
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();