首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >N2 CMS分级用户控件

N2 CMS分级用户控件
EN

Stack Overflow用户
提问于 2009-03-03 20:56:39
回答 2查看 642关注 0票数 1

我目前正在把一个网站放在N2的内容管理系统框架中。我想做的一件事是能够让用户使用相当标准的星级评分风格的用户控件或类似的东西对网站的各种元素进行评分。

有没有人看起来特别像在N2中实现了类似的东西?我只是在寻找一些在N2中实现这一点的最佳方法。

此外,我不认为这会有什么不同,但我目前正在使用N2中的ASP实现所有这些功能。

提前感谢

保罗

EN

回答 2

Stack Overflow用户

发布于 2009-03-03 21:17:22

检查BlogSvc (即将命名为AtomServer)的source code

Source/WebCore/Plugins/Rater/RaterService.cs

下面是一个代码片段:

代码语言:javascript
复制
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
  };
}
票数 0
EN

Stack Overflow用户

发布于 2012-12-13 23:42:15

这是我在我的网站上用来给内容打分的东西--1到5星

N2CMS - EditableEnum非常适合这项工作

代码语言:javascript
复制
    [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
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/608149

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档