1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Generic Content by Category

Generic Content by Category

13 posts, 1 answered
  1. Bryan
    Bryan avatar
    62 posts
    Registered:
    20 Jul 2010
    26 Aug 2010
    Link to this post
    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


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    27 Aug 2010
    Link to this post
    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
  3. Bryan
    Bryan avatar
    62 posts
    Registered:
    20 Jul 2010
    30 Aug 2010
    Link to this post
    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
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    30 Aug 2010
    Link to this post
    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
    Answered
  5. Bryan
    Bryan avatar
    62 posts
    Registered:
    20 Jul 2010
    31 Aug 2010
    Link to this post
    Thanks Ivan.  That did it!

    Bryan
  6. Bryan
    Bryan avatar
    62 posts
    Registered:
    20 Jul 2010
    06 Oct 2010
    Link to this post
    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


  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Oct 2010
    Link to this post
    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
  8. Kiran
    Kiran avatar
    12 posts
    Registered:
    14 Sep 2010
    19 Nov 2010
    Link to this post
    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
  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    19 Nov 2010
    Link to this post
    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
  10. Paolo
    Paolo avatar
    147 posts
    Registered:
    11 Jun 2009
    27 Jan 2011
    Link to this post
    Hello Ivan,
    can you please tell me how do I get the content items passing the category taken from the taxonomy?
    Thanks

    Paolo
  11. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    27 Jan 2011
    Link to this post
    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
  12. Wagner
    Wagner avatar
    21 posts
    Registered:
    05 May 2011
    01 Feb 2012
    Link to this post
    Great thread, it was all I was looking for, thanks!  :)
  13. Nick
    Nick avatar
    10 posts
    Registered:
    09 Jun 2008
    07 Mar 2012
    Link to this post

    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;
            }
13 posts, 1 answered