Beispiel #1
0
        /// <summary>
        /// add single rating to the database or update it with new value
        /// </summary>
        ///
        /// <param name="song">
        /// song to add the rating to
        /// </param>
        ///
        /// <param name="ratingUser">
        /// who's adding this rating?
        /// </param>
        ///
        /// <param name="rating">
        /// rating value: either 1 or -1
        /// </param>
        ///
        /// <returns>
        /// A boolean indicating if rating was in the right input range (between -1 to 1)
        /// </returns>
        public virtual PlaylistSongRating RateSong(PlaylistSongRating playlistSongRating, FbUser ratingUser, short rating,  bool isAddedByAdmin = false, bool isNewSong = false)
        {
            if (PlaylistSongRating.IsRatingValueInvalid(rating))
            {
                return null;
            }

            RatingStatus ratingType = RatingStatus.NothingNew;
            //var currentStatistics = GetCurrentStatistics(song);

            if (isAddedByAdmin) //if admin votes the song give it a special treatment
            {                   
                if (playlistSongRating.AdminRating != 0 && rating == 0)    //admin just cleared his vote
                {
                    ratingType = RatingStatus.RemovedRating;
                }

                if (playlistSongRating.AdminRating == 0 && rating != 0) //admin switched between positive and negative score
                {                                                     
                    ratingType = RatingStatus.AddedNewRating;
                }

                if (playlistSongRating.AdminRating == 0 && rating == 0) //admin added song but didn't rate it (can be achieved through harvesting)
                {
                    ratingType = RatingStatus.AddedNewEmptyRating;
                }

                playlistSongRating.SetAdminRating(playlistSongRating.AdminRating, rating, isNewSong);
                playlistSongRating.AdminRating = rating;
            }
            else 
            {
                ratingType = playlistSongRating.AddRating(ratingUser, rating);
            }

            //note: AddRating also adds points to user as well as advances the NumberOfVotes and NumberOfSongs counters
            UpdateAggregatedInfo(ratingType, ratingUser, isNewSong, isAddedByAdmin);
            return playlistSongRating;
        }