1

我目前正在 N2 CMS 框架中构建一个站点。我想做的一件事是能够让用户使用相当标准的星级式用户控件或类似的东西对网站的各种元素进行评分。

有没有人特别在 N2 中实现了与此类似的东西?只是寻找一些关于在 N2 中实现这一目标的最佳方法的指示。

另外,不要认为它应该有所作为,但我目前正在 N2 中使用 ASP MVC 实现所有这些。

提前致谢

保罗

4

2 回答 2

0

查看 BlogSvc 的源代码(即将被称为 AtomServer)

源/WebCore/Plugins/Rater/RaterService.cs

这是一个片段:

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
  };
}
于 2009-03-03T21:17:21.937 回答
0

这就是我在我的网站上用于对内容进行评级的内容 - 1 到 5 星

N2CMS - EditableEnum 非常适合这项工作

    [EditableEnum("RatingValue", 2, typeof(Rating))]
    public virtual string RatingValue
    {
        get { return (string)(GetDetail("RatingValue")); }
        set { SetDetail("RatingValue", value); }
    }

    /// <summary>
    /// Enum for the Vehicle Review Ratings
    /// </summary>
    public enum Rating
    {
        one = 1,
        two = 2,
        three = 3,
        four = 4,
        five = 5
    }
于 2012-12-13T15:42:15.297 回答