Mono Support RatingBLL Api not working correctly? 

Viewed 23386 time(s), 3 post(s), 6/22/2016 9:49:39 AM - by ncole
6/22/2016 9:50:07 AM
60 Reputation 8 Total posts

Hi,
 

Im trying to implement a like/dislike feature for Discussion Messages. To do this I am using two buttons one which saves rating of 1 (dislike) and one which saves rating as 5 (like). 
 
For each message I am trying to then calculate how many likes /dislike it has by using :
 
var msgRatings = DependencyInjectionFactory.Resolve<IRatingBLL>()
                        .GetRatingCollection(msg.Id,
                            (int)EntityType.SnDiscussionMessageEntity, false, 100000);
 
however this seems to return all ratings currently stored in the database.
 
Similarly when I save a rating it seems to save it against the same item  even if i pass different Guids:
  
protected void Like(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton) sender;
            DependencyInjectionFactory.Resolve<IRatingBLL>()
                .SaveRating(5, SecurityUtility.GetUserId(), Guid.Parse(lb.CommandArgument),
                    (int) EntityType.SnDiscussionMessageEntity);
        }

 Can someone explain what I am doing wrong and why this is not working?
 
Thanks

1
6/23/2016 10:53:43 AM
109 Reputation 20 Total posts

Hi ncole,

In order to get the number of likes/dislikes you will need to make two custom service methods that will include the filters for rating(SnRating.Rating == 1 for dislikes, SnRating.Rating == 5 for likes) and will return the total number of likes/dislikes.

The SaveRating method creates a new SnRatingEntity record for each rating and connects them to their parent entity via the SnRelationship table.
Can you provide us some more information on this issue you are having? Perhaps the data from the SnRating and SnRelationship table to see how these records are connected. Also, can you give us the values of the CommandArgument property you are passing into the SaveRating method? 

Regards,
Daniel 

2
7/7/2016 10:37:29 AM
60 Reputation 8 Total posts

for anyone else... the problem was this:
 


 
I was using (int) EntityType.SnDiscussionMessageEntity instead of (int)SnEntityType.DiscussionMessage
 
I don't really know the difference or why this worked but changing the code to this works:
 
 protected void Like(object sender, EventArgs e)
        {
            LinkButton lb = (LinkButton)sender;
            DependencyInjectionFactory.Resolve<IRatingBLL>()
                .SaveRating(5, SecurityUtility.GetUserId(), Guid.Parse(lb.CommandArgument),
                    (int)SnEntityType.DiscussionMessage);
            ConfigureMessages();
        }

3
This is a demo site for MonoX. Please visit Mono Software for more info.