Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
14 | Developer’s <strong>Guide</strong> <strong>EPiServer</strong> Community 3.1<br />
The <strong>EPiServer</strong> Community tag system allows for each entity class to have their own ID domain. However, it is required<br />
that the combination of entity type and a single integer ID uniquely specifies an instance of the entity class.<br />
For the tag system to be able to recreate the objects there must be an EntityProvider configured for the Type that has<br />
been tagged. Providers are already configured for all relevant <strong>EPiServer</strong> Community objects.<br />
2.3 Rating<br />
The rating system allows for rating of objects that implements the IRatableEntity interface. A Rating is defined as the<br />
object to rate, the rating value and the rater. Rated entities can then for example be retrieved by the average rate. The<br />
use the Rating system, first import the necessary namespace:<br />
using StarCommunity.Core.Modules;<br />
using StarCommunity.Core.Modules.Security;<br />
using StarCommunity.Core.Modules.Rating;<br />
using StarCommunity.Modules.Blog; //only for this example.<br />
2.3.1 Rating an entity<br />
In this example we use a Blog to rate. However, the similar approach is taken for all ratable entities.<br />
//Get the rating user by id<br />
IUser user =<br />
(IUser)StarCommunitySystem.CurrentContext.DefaultSecurity.GetUser(1234);<br />
//Get the blog to rate by id<br />
Blog b = BlogHandler.GetBlog(1);<br />
//Create a rating object with the rating value 3<br />
IRating rating = new Rating(b, 3, new UserAuthor(user));<br />
//Rate the blog<br />
RatingHandler.Rate(rating);<br />
2.3.2 Examine if a entity is already rated by an user<br />
It may be of interest to see if a ratable entity has already been rated by a specific user. We call the HasRated method in<br />
the RatingHandler. In the example below, the method would return true.<br />
RatingHandler.HasRated(b, new UserAuthor(user));<br />
2.3.3 Retrieving ratings for an entity<br />
There are many different overloads for getting ratings for a specific item. The example below shows how to get all<br />
ratings for Blog b, rated by a specific user<br />
RatingCollection ratingCollection =<br />
b.GetRatings(new UserAuthor(user), 1, 10, out totalItems);<br />
© <strong>EPiServer</strong> AB