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; }