Beispiel #1
0
        //--- Methods ---
        public virtual RatingBE Copy()
        {
            RatingBE r = new RatingBE();

            r.Id               = Id;
            r.ResourceId       = ResourceId;
            r.ResourceType     = ResourceType;
            r.Score            = Score;
            r.Timestamp        = Timestamp;
            r.ResourceRevision = ResourceRevision;
            r.TimestampReset   = TimestampReset;
            r.UserId           = UserId;
            return(r);
        }
        //--- Methods ---
        public static void SetRating(PageBE page, UserBE user, float? score) {
            ThrowOnInvalidLicense();
            RatingBE currentRating = DbUtils.CurrentSession.Rating_GetUserResourceRating(user.ID, page.ID, ResourceBE.Type.PAGE);

            if(score == null) {
                if(currentRating == null) {

                    // no rating exists currently: noop
                    return;
                }

                // reset a user ratings for a page
                DbUtils.CurrentSession.Rating_ResetUserResourceRating(user.ID, page.ID, ResourceBE.Type.PAGE, DreamContext.Current.StartTime);
            } else {

                // set or update a page rating

                // Valid score is limited to 0 and 1.
                if(score != 0 && score != 1) {
                    throw new Exceptions.InvalidRatingScoreException();
                }

                if(currentRating != null && currentRating.Score == score) {

                    // an equal score already exists: noop
                    return;
                }

                RatingBE rating = new RatingBE();
                rating.ResourceId = page.ID;
                rating.ResourceType = ResourceBE.Type.PAGE;
                rating.ResourceRevision = page.Revision;
                rating.Timestamp = DreamContext.Current.StartTime;
                rating.TimestampReset = null;
                rating.UserId = user.ID;
                rating.Score = score.Value;

                // Set a new rating
                DbUtils.CurrentSession.Rating_Insert(rating);
            }
            // Trigger a notification
            DekiContext.Current.Instance.EventSink.PageRated(DreamContext.Current.StartTime, page, user);
        }
Beispiel #3
0
 //--- Methods ---
 public virtual RatingBE Copy() {
     RatingBE r = new RatingBE();
     r.Id = Id;
     r.ResourceId = ResourceId;
     r.ResourceType = ResourceType;
     r.Score = Score;
     r.Timestamp = Timestamp;
     r.ResourceRevision = ResourceRevision;
     r.TimestampReset = TimestampReset;
     r.UserId = UserId;
     return r;
 }
 public void Rating_ResetUserResourceRating(uint userId, ulong resourceId, RatingBE.Type resourceType, DateTime resetTimestamp) {
     Stopwatch sw = Stopwatch.StartNew();
     _next.Rating_ResetUserResourceRating(userId, resourceId, resourceType, resetTimestamp);
     LogQuery(CATEGORY_RATINGS, "Rating_ResetUserResourceRating", sw, "userId", userId, "resourceId", resourceId, "resourceType", resourceType, "resetTimestamp", resetTimestamp);
 }
 public RatingBE Rating_GetUserResourceRating(uint userId, ulong resourceId, RatingBE.Type resourceType) {
     Stopwatch sw = Stopwatch.StartNew();
     var ret = _next.Rating_GetUserResourceRating(userId, resourceId, resourceType);
     LogQuery(CATEGORY_RATINGS, "Rating_GetUserResourceRating", sw, "userId", userId, "resourceId", resourceId, "resourceType", resourceType);
     return ret;
 }
 public void Rating_Insert(RatingBE rating) {
     Stopwatch sw = Stopwatch.StartNew();
     _next.Rating_Insert(rating);
     LogQuery(CATEGORY_RATINGS, "Rating_Insert", sw, "rating", rating);
 }