More in this section

Forums / Bugs & Issues / Comments For Blogs

Comments For Blogs

14 posts, 0 answered
  1. Anu
    Anu avatar
    72 posts
    Registered:
    17 Jun 2010
    02 Jul 2011
    Link to this post
    Hello Admin,
            I am using following query to Retrive Commnet for given Post 

        

    1 - IQueryable

    <Comment> comments = manager.GetComments().Where(t => t.CommentedItemID == allPosts.Id);

    2 - List<Guid> ilistGuid = new List<Guid> { guid };  

    IQueryable<Comment> postToLocate = manager.GetComments();

     

    postToLocate.Where(p => p.CommentedItemID.Equals(allPosts.Id));

    1- Query returning me following error
    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.  and the Error Attached

    2- Second Query returning me all the Comments though i have Specified
    p => p.CommentedItemID.Equals(allPosts.Id)


    Please tel me the Solution

    Thanks & Regards
    Anu.

  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    04 Jul 2011
    Link to this post
    Hello Anu,

    Could you try to expose the ID which you use to filter the items as a local variable or pass it as a string into the expression?

    Greetings,
    Ivan Dimitrov
    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
  3. Anu
    Anu avatar
    72 posts
    Registered:
    17 Jun 2010
    05 Jul 2011
    Link to this post
    Helloo Admin,

    1) I tried with following

     

     

        IQueryable<Comment> comments = manager.GetComments().Where(t => t.CommentedItemID == new Guid("5939c218-8f71-4f07-be00-950627bc122c"));

     


     

     

        IQueryable<Comment> postToLocate = manager.GetComments()

     

    .Where(p => p.ParentGroupIds.Contains(

     

    new Guid("5939c218-8f71-4f07-be00-950627bc122c")));

     


        But still im getting the error ...


    2 ) Please refer the Attach which displays All d post of Blog With No of Count of Comments if thr else Go Comment ...

    In the following query to retrive Blog Post im Getting Comments count as 0 though i have added comments for the Post ...

    Im binding the source to the ListView in ItemsList_ItemDataBound event im getting as ...

     

    protected void ItemsList_ItemDataBound(object sender, ListViewItemEventArgs e)

     

    {

        if (e.Item.ItemType == ListViewItemType.DataItem) 

        { 

            ListViewDataItem ldr = (ListViewDataItem)e.Item;
            --- Over here below value im getting 0
     

           ((Telerik.Sitefinity.GenericContent.Model.Content)(ldr.DataItem)).Comments.Count
        }
    }

    BlogsManager

    manager = BlogsManager.GetManager();  

    var allPosts = manager.GetBlogPosts()  

    .Where(s => s.Status == ContentLifecycleStatus.Live);  

     

    var sortedPost =  

    from p in allPosts  

    orderby p.PublicationDate descending 
    select p;

    Please Help ... where im getting wrong ?

    Thanks & Regards
    Anu.

     

  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Jul 2011
    Link to this post
    Hi Anu,

    Why you cast the data item which should be a BlogItem to Telerik.Sitefinity.GenericContent.Model.Content instead of the blog model?

    Regards,
    Ivan Dimitrov
    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
  5. Anu
    Anu avatar
    72 posts
    Registered:
    17 Jun 2010
    05 Jul 2011
    Link to this post
    Hello Ivan,
            
    I thought using ((Telerik.Sitefinity.GenericContent.Model.Content)(ldr.DataItem)).Comments   this will return me the number of comments for each post ...

    Can u tel me the way of retrving the Comment for each Post ( Same as BlogPost Control of Sitefinity Which displays 'Go Comment' Or 'No Of Comment' )

    Thanks & Regards ...
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    05 Jul 2011
    Link to this post
    Hi Anu,

    Please consider the code shown below

    var posts = App.WorkWith().BlogPosts().Get(); // user where clause if you want to get posts froma a given parent
             if (posts.Count() > 0)
             {
                 var listofAllComments = new List<Comment>(); // this is a list that will collect all comments
                 foreach (BlogPost post in posts)
                 {
                     if (post.Comments.Count > 0)
                     {
                         var commentsForSinglePost = post.Comments;
                         foreach (Comment c in commentsForSinglePost)
                         {
                             listofAllComments.Add(c);
                         }
     
                     }
                 }
             }


    All the best,
    Ivan Dimitrov
    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
  7. Anu
    Anu avatar
    72 posts
    Registered:
    17 Jun 2010
    05 Jul 2011
    Link to this post
    Hello Ivan,
    I tried ur code still im getting Comment Count as 0

    i m using SItefinitis following method to Insert Comment for gievn Blog Post

    BlogPost

    allPosts = manager.GetBlogPost(guid);  

    //Create a comment item   

    Comment comment = manager.CreateComment(allPosts);  

    //Set the comments properties  

    comment.Content = content;

    comment.AuthorName = author_name;

    comment.Website = website;

    comment.Email = email;

    comment.IpAddress = ip_address;

    comment.CommentStatus = 

    CommentStatus.Hidden;  

    //save the changes  

    manager.SaveChanges();

    I found tht this method dosent Insert values in 'sf_blog_posts_sf_commnt' Table ... coz of tht im getting Comment Count as 0 ...

    Is ther any Solution for this ?

    Thanks & Regards
    Anu.

  8. Shailendra
    Shailendra avatar
    16 posts
    Registered:
    12 Apr 2011
    06 Jul 2011
    Link to this post
    Hello Ivan,

    I just Inserted Comment for 1 Post using SItefinity Default 'BlogPost' Template ( Drag n Drop tht control on page ) and then i Published tht Comment.
    After tht i tried to retrive the same using

    var posts = App.WorkWith().BlogPosts().Get(); // user where clause if you want to get posts froma a given parent
             if (posts.Count() > 0)
             {
                 var listofAllComments = new List<Comment>(); // this is a list that will collect all comments
                 foreach (BlogPost post in posts)
                 {
                     if (post.Comments.Count > 0)
                     {
                         var commentsForSinglePost = post.Comments;
                         foreach (Comment c in commentsForSinglePost)
                         {
                             listofAllComments.Add(c);
                         }
     
                     }
                 }
             }


    But it dosent return me tht Published Comment ...
    I want to Display Post n its No of Comments on Page ( Created User Controls for the Same ) ...

    What is the Solution for this ...

    Thanks & Regards
    Anu.


  9. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Jul 2011
    Link to this post
    Hello Shailendra,

    Most probably you have not assigned the comment to the blog post (with status Live) . I am sending you sample code that illustrates how to get the first blog post and crate comment for it. Then get the comment for this post.

    var manager = BlogsManager.GetManager();
    var firstpost = manager.GetBlogPosts().Where(myb => myb.Status == ContentLifecycleStatus.Live).First();
    var comment = manager.CreateComment(firstpost);
    comment.AuthorName = "test111";
    comment.Content = "test111";
    comment.Email = "test11@sa.ss";
    comment.Website = "http://www.telerik.com";
    comment.DateCreated = DateTime.UtcNow;
    comment.IpAddress = "127.0.0.1";
    firstpost.Comments.Add(comment);
    manager.SaveChanges();
     
     
    var facade = App.WorkWith().BlogPosts();
    var posts = facade.Get(); // user where clause if you want to get posts froma a given parent
    if (posts.Count() > 0)
    {
        var listofAllComments = new List<Comment>();
        foreach (BlogPost post in posts)
        {
            if (post.Comments.Count > 0)
            {
                var commentsForSinglePost = post.Comments;
                foreach (Comment c in commentsForSinglePost)
                {
                    listofAllComments.Add(c);
                }
     
            }
        }
    }

    I also attached a short video that illustrates how the code works and create this comment without issues, then the comments are updated from 1 to 2 - in the code check and at the backend UI.


    Best wishes,
    Ivan Dimitrov
    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
  10. JingYuan
    JingYuan avatar
    12 posts
    Registered:
    18 Jul 2011
    28 Jul 2011
    Link to this post
    How to get the blogpost.Comment Count  in widget template?

    Blog posts >> edit  >> List Setting >> myTemplate >> edit

    Comments: <%# Eval("Comments.Count")%> returning 0 (zero) for a blogpost with comment of count 2
  11. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    01 Aug 2011
    Link to this post
    Hello Jingyuan,

    Use <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfpostCommentsCount"/> which by default display link to the comments. IF you want to display the comments just as text without link add enabled="false".

    Regards,
    Stanislav Velikov
    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
  12. JingYuan
    JingYuan avatar
    12 posts
    Registered:
    18 Jul 2011
    01 Aug 2011
    Link to this post
    Thank you, Stanislav.
  13. JingYuan
    JingYuan avatar
    12 posts
    Registered:
    18 Jul 2011
    04 Aug 2011
    Link to this post
    Hi Stanislav. or any Admin,

    Regarding <sf:CommentsBox ID="itemCommentsLink" runat="server" CssClass="sfpostCommentsCount"/>

    how to show "0 comment" instead of "Go comment" when the comment for post is ZERO?
  14. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    04 Aug 2011
    Link to this post
    Hi Jingyuan,

    Add HyperLinkNoCommentsText property to CommentsBox
    <sf:CommentsBox ID="itemCommentsLink" runat="server" HyperLinkNoCommentsText="0" />

    Greetings,
    Stanislav Velikov
    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
14 posts, 0 answered