views:

357

answers:

1

Hi all,

I'm currently putting together a site in the N2 CMS framework. One of things I'd wanted to do was to be able to have users rate various elements of the site using a fairly standard star rating-style user control or something similar.

Has anyone seem anything similar to this implemented within N2 specifically? Just looking for some pointers as to the best way to achieve this in N2.

Also, don't think it should make a difference, but I'm currently implementing all this using ASP MVC within N2.

Thanks in advance

Paul

A: 

Check the source code of BlogSvc (soon to be called AtomServer)

Source/WebCore/Plugins/Rater/RaterService.cs

Here is a snippet:

public RaterModel Rate(Id entryId, float rating, User user, string ip)
{
  LogService.Info("RateEntry: {0}, {1}, {2}", entryId, rating, ip);

  if (!AuthorizeService.IsAuthorized(user, entryId, AuthAction.RateEntryOrMedia))
    throw new UserNotAuthorizedException(user.Name, AuthAction.RateEntryOrMedia.ToString());

  if (rating < 1 || rating > 5) throw new ArgumentOutOfRangeException("Rating value must be 1 thru 5.");

  AtomEntry entry = AtomEntryRepository.GetEntry(entryId);
  if (entry.Raters.Contains(ip)) throw new UserAlreadyRatedEntryException(ip, entry.Id.ToString());

  entry.RatingCount++;
  entry.RatingSum += (int)Math.Round(rating); //temporarily force int ratings
  entry.Edited = DateTimeOffset.UtcNow;
  List<string> raters = entry.Raters.ToList();
  raters.Add(ip);
  entry.Raters = raters;
  entry = AtomEntryRepository.UpdateEntry(entry);
  return new RaterModel()
  {
    PostHref = RouteService.RouteUrl("RaterRateEntry", entryId),
    Rating = entry.Rating,
    CanRate = false,
    RatingCount = entry.RatingCount
  };
}
JarrettV
Helpful link, but wasn't quite what I was looking for, ideally needed something integrated with N2 better. Thanks though.
Chops