Generic Content by Category
I am trying to list generic content by category using the Fluent API. My approach is this:
IList<ContentItem> result = App.WorkWith().ContentItems()
.Where(item => item.CategoryText ==
this
.categoriesText)
.Get()
.ToList();
Hello Bryan,
Try using this code
var content = App.WorkWith()
.ContentItems()
.Where(ci => ((IList<Guid>)ci.GetValue(
"Category"
)).Contains(cat1Id));
Thanks for the reply Ivan.
Hi Bryan,
You have to add using Telerik.Sitefinity.Model and you should be able to call GetValue. In the BETA there are no methods in the fluent API that allows you to retrieve DynamicFileds data directly. We have logged a task for exposing such methods. Currently, the easiest way is using GetValue
as my code shows.
All the best,
Ivan Dimitrov
the Telerik team
Thanks Ivan. That did it!
Hey Ivan, I am in the process of upgrading to beta 2. Did the extension methods move to a different namespace?
Hello Bryan,
The namespace is still Telerik.Sitefinity.Model. We are in process of changing the API and this is why AlbumSingularFacade is returned by Albums() method. You could use this code instead
var manager = LibrariesManager.GetManager(LibrariesManager.GetDefaultProviderName());
var alb = manager.GetAlbums().Where(....).SingleOrDefault();
Hi Ivan,
I have tried the below code and got it working.
var content = App.WorkWith()
.ContentItems()
.Where(ci => ((IList<Guid>)ci.GetValue(
"Category"
)).Contains(cat1Id));
Hi Kiran,
cat1Id is the id of your taxon. Below is a sample that shows how to get the Taxa Id by name.
var taxonomyManager = TaxonomyManager.GetManager();
var c =
"categories"
;
var taxonomy1 = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name == c).SingleOrDefault();
var b = taxonomy1.Taxa.Where(t => t.Name ==
"test"
).SingleOrDefault();
Hello Ivan,
can you please tell me how do I get the content items passing the category taken from the taxonomy?
Thanks
Paolo
Hello,
Please take a look at this forum post
Best wishes,
Ivan Dimitrov
the Telerik team
Great thread, it was all I was looking for, thanks! :)
Hi Ivan.
I ran into an exception when you delete a category. This code seems to get around it.
/// <summary>
/// Get the category ID by the category name
/// </summary>
/// <param name="categoryName">Name of the category. Must be an exact match</param>
/// <returns>Guid of category, or empty guid if null</returns>
private Guid GetCategoryIDByCategoryName(string categoryName)
Guid id = Guid.Empty;
try
TaxonomyManager taxonomyManager = TaxonomyManager.GetManager();
string taxonomyName = "categories";
HierarchicalTaxonomy taxonomy1 = taxonomyManager.GetTaxonomies<HierarchicalTaxonomy>().Where(t => t.Name.ToLower() == taxonomyName.ToLower()).SingleOrDefault();
if (taxonomy1 != null)
var taxonomyForCategory = taxonomyManager.GetTaxa<HierarchicalTaxon>().Where(t => t.Name.ToLower() == categoryName.ToLower()).Single();
if (taxonomyForCategory != null)
id = taxonomyForCategory.Id;
catch (Exception ex)
//Logging.LogWarning("Error getting news rotator category taxonomy", ex);
return id;