N2 CMS 评级用户控制

发布于 2024-07-14 21:26:06 字数 231 浏览 5 评论 0原文

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

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

另外,我认为这不会产生什么影响,但我目前正在 N2 中使用 ASP MVC 来实现这一切。

预先感谢

保罗

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烦人精 2024-07-21 21:26:06

检查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
  };
}

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
  };
}
白色秋天 2024-07-21 21:26:06

这就是我在网站中使用的内容评级 - 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
    }

This is what i use in my website for rating content - 1 to 5 stars

N2CMS - EditableEnum works perfectly for this job

    [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
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文