我目前正在把一个网站放在N2的内容管理系统框架中。我想做的一件事是能够让用户使用相当标准的星级评分风格的用户控件或类似的东西对网站的各种元素进行评分。
有没有人看起来特别像在N2中实现了类似的东西?我只是在寻找一些在N2中实现这一点的最佳方法。
此外,我不认为这会有什么不同,但我目前正在使用N2中的ASP实现所有这些功能。
提前感谢
保罗
发布于 2009-03-03 21:17:22
检查BlogSvc (即将命名为AtomServer)的source code
Source/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
};
}发布于 2012-12-13 23:42:15
这是我在我的网站上用来给内容打分的东西--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
}https://stackoverflow.com/questions/608149
复制相似问题