Anonymous rating

Vote:
 

Hi

I have a question about anonymous ratings. It seems it is not possible to rate more than once per user which is understandable. In order to rate anonymously one has to rate with the user Anynymous which means that this can only be done once. Is there any way around this? I have tried using null instead of author when creating a ratings object but this is not allowed. See the code below.

            if (userId != "") CommunitySystem.CurrentContext.DefaultSecurity.GetUser(Convert.ToInt32(userId));

            IRating rater = new Rating(answer, Convert.ToDouble(vote), userId == "" ? null : user.GetAuthor());
            RatingHandler.Rate(rater);
            ExpertHandler.UpdateAnswer(answer);

 

We are running EPiServer Community 3.2.5 with episerver CMS 5.2

#43658
Sep 21, 2010 9:45
Vote:
 

..and to make anonymous ratings the following code was used

IUser user = CommunitySystem.CurrentContext.DefaultSecurity.GetUserByUserName(
PageReference.StartPage.SiteSettings().GetProperty<string>("AnonymousUserName"));
IAuthor theAuthor = AuthorHandler.GetAnonymousAuthor(user, PageReference.StartPage.SiteSettings().GetProperty<string>("AnonymousUser"));

#43659
Sep 21, 2010 10:16
Vote:
 

Sounds like you need a GuestAuthor. How to stop users from posting multiple ratings is a different problem, perhaps just use a cookie to store what entities the guest has already rated.

#43664
Sep 21, 2010 11:33
Vote:
 

What do you mean by GuestAuthor?

We already have a cookie to prevent users from rating several times. The problem is that when not logged in it is supposed to be possible to rate once per anynymous "computer". However it is only possible to add one rating per user in Relate+ and since anonymous author is a based on a user only the first anonymous user can rate. When rating a second time for the same user in Relate the previous rating is over written. What we want is to be able to vote several times anonymously, once per computer. The once per computer part is already solved by our cookie.

How can I solve this?

#43666
Sep 21, 2010 12:57
Vote:
 

There are several implementations of the IAuthor interface, UserAuthor is only one. Another is GuestAuthor, which sounds perfect for your situation. You have declared your "theAuthor" as an IAuthor, so I assume you can use the GuestAuthor instead, like so: IAuthor theAuthor = new GuestAuthor([any string you like here]);

 

#43667
Sep 21, 2010 13:25
Vote:
 

Thanx, that worked like a charm! However the code is ugly.. I would appreciate an empty constructor for better usability since the key probably is the email or the email in conjunction with the name.

string uniqueVisitor = DateTime.Now.Ticks.ToString();
guestAuthor = new GuestAuthor(uniqueVisitor,String.Format("{0}@bar.com",uniqueVisitor));

 

#43681
Edited, Sep 21, 2010 16:20
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.