public static UserDTO Map(PlaylistSongRating playlistSongRating, FbCookieInfo cookieInfo) { return Mapper.Map<PlaylistSongRating, UserDTO>(playlistSongRating); }
public static SongWithUserRatingDTO Map(PlaylistSongRating rat, bool isAdmin = false) { var ratVal = Mapper.Map<PlaylistSongRating, SongWithUserRatingDTO>(rat); ratVal.Member = MemberDTOFactory.Map<MemberDTO>(rat.Creator, rat, isAdmin); return ratVal; }
public virtual PlaylistSongRating AddSong(Song song, FbUser user, bool addedByAdmin, short rating = 1) { var playlistSongRating = new PlaylistSongRating { Playlist = this, Song = song, Creator = user }; Ratings.Add(playlistSongRating); var palylistSongRating = RateSong(playlistSongRating, user, rating, addedByAdmin, true); if (addedByAdmin) { palylistSongRating.IsAddedByAdmin = true; } return palylistSongRating; }
public virtual PlaylistSongRating DetachSong(PlaylistSongRating playlistSongRating, FbUser user) { if (playlistSongRating != null) { Ratings.Remove(playlistSongRating); NumberOfVotes -= playlistSongRating.Details.Count(detail=>detail.Rating!=0); NumberOfVotes -= Math.Abs(playlistSongRating.AdminRating); NumberOfSongs--; //TODO: enhance this efficiency, move this to nhibernate layer. Currently alright for this usage, but might be heavy. foreach (var detail in playlistSongRating.Details.Select(_detail=>_detail.VotingUser)) { var userPlaylistInfo = detail.PlaylistsInfo.FirstOrDefault(pInfo => pInfo.Playlist == this); if(userPlaylistInfo!= null) userPlaylistInfo.NumOfVotes--; } //we don't reward the owner of the playlist, it's not fair if (playlistSongRating.IsOwner(user.Id)) { RewardUser(user, UserPlaylistInfo.Operation.DeleteSong); if (playlistSongRating.Details.Any(details => details.VotingUser == user && details.Rating!=0)) { RewardUser(user, UserPlaylistInfo.Operation.RemoveSongRating); } } } return playlistSongRating; }
/// <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; }