MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

RatingBLL Api not working correctly?  (Mono Support )

Viewed 10150 time(s), 3 post(s) 6/22/2016 9:49:39 AMby ncole
ncole

ncole

6/22/2016 9:50:07 AM
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

This content has not been rated yet. 
60 Reputation 8 Total posts
dcaklovic

dcaklovic

6/23/2016 10:53:43 AM
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 
This content has not been rated yet. 
109 Reputation 20 Total posts
ncole

ncole

7/7/2016 10:37:29 AM
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();
        }
This content has not been rated yet. 
60 Reputation 8 Total posts