Generic Content by Category

Posted by Community Admin on 03-Aug-2018 21:34

Generic Content by Category

All Replies

Posted by Community Admin on 26-Aug-2010 00:00

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();
However, item.CategoryText is empty even though a content item is assigned a category in the CMS backend.  Any ideas?

Thanks,
Bryan


Posted by Community Admin on 27-Aug-2010 00:00

Hello Bryan,

Try using this code

var content = App.WorkWith()
              .ContentItems()
              .Where(ci => ((IList<Guid>)ci.GetValue("Category")).Contains(cat1Id));

This will return the content items that belong to specified category.

Regards,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 30-Aug-2010 00:00

Thanks for the reply Ivan.


ContentItem does not have a GetValue(string) method.  As a basic feature, shouldn't CategoryText provide the text of the categories applied to the content item?  Is this just incomplete in the Beta?

Thanks,
Bryan

Posted by Community Admin on 30-Aug-2010 00:00

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

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 31-Aug-2010 00:00

Thanks Ivan.  That did it!


Bryan

Posted by Community Admin on 06-Oct-2010 00:00

Hey Ivan, I am in the process of upgrading to beta 2.  Did the extension methods move to a different namespace?


I am having the same issues with other functionality I have built as well (such as Albums, for example).

It appears that App.WorkWith().Albums() returns an AlbumSingularFacade rather than an AlbumPluralFacade which does have a Where(Exrpression<Func> what) method.  Is this intentional?

Thanks,
Bryan


Posted by Community Admin on 06-Oct-2010 00:00

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


Greetings,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 19-Nov-2010 00:00

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

But I would like to know what needs to be passed for "cat1Id". Is it GUID of of the category? If so how can we get the GUID of a category?

Once we get the content items after we filter by category how can we extract the html from the content items. Could you please provide me a sample code which gets me html from a content item returned by the above line of code? I have tried with a method "GetString()" but it was giving me some runtime exceptions.

Thanks,
Kiran

Posted by Community Admin on 19-Nov-2010 00:00

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

After you filter the list you can use ContentItem class properties to get the Content of the item.

Sincerely yours,
Ivan Dimitrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 27-Jan-2011 00:00

Hello Ivan,
can you please tell me how do I get the content items passing the category taken from the taxonomy?
Thanks

Paolo

Posted by Community Admin on 27-Jan-2011 00:00

Hello,

Please take a look at this forum post

Best wishes,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about 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 01-Feb-2012 00:00

Great thread, it was all I was looking for, thanks!  :)

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


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;
       

This thread is closed