public ActionResult AddVote(int vote, long id)
        {
            var user        = userManager.ReadUser(User != null ? User.Identity.Name : testName);
            var createdVote = playlistManager.CreateVote(vote, user.Id, id);

            if (createdVote == null)
            {
                return(new HttpStatusCodeResult(400, "You have reached your vote limit for this playlist"));
            }

            var playlistTrack = playlistManager.ReadPlaylistTrack(id);
            var playlistId    = playlistTrack.Playlist.Id;

            var viewmodel = new LivePlaylistTrackViewModel
            {
                Id    = playlistTrack.Id,
                Score = playlistTrack.Votes.Sum(v => v.Score),
                Track = playlistTrack.Track
            };

            var context = GlobalHost.ConnectionManager.GetHubContext <PlaylistHub>();

            context.Clients.Group(playlistId.ToString()).scoreUpdated(id, viewmodel);

            return(new HttpStatusCodeResult(200));
        }
        public IHttpActionResult Upvote(long id, long trackId)
        {
            var userIdentity = RequestContext.Principal.Identity as ClaimsIdentity;
            var user         = GetUser(userIdentity);
            var createVote   = playlistManager.CreateVote(1, user.Id, trackId);

            var playlistTrack = playlistManager.ReadPlaylistTrack(trackId);
            var viewmodel     = new LivePlaylistTrackViewModel
            {
                Id    = playlistTrack.Id,
                Score = playlistTrack.Votes.Sum(v => v.Score),
                Track = playlistTrack.Track
            };

            var context = GlobalHost.ConnectionManager.GetHubContext <PlaylistHub>();

            context.Clients.Group(id.ToString()).scoreUpdated(trackId, viewmodel);

            return(Ok(createVote));
        }
        public void GetLivePlaylistWithNoTracksPlayedButOneVoted()
        {
            var votedTrack    = playlist.PlaylistTracks.First();
            var notVotedTrack = playlist.PlaylistTracks.Last();

            playlistManager.CreateVote(1, user.Id, votedTrack.Id);

            List <LivePlaylistTrackViewModel> livePlaylistTracks = new List <LivePlaylistTrackViewModel>();

            livePlaylistTracks.Add(new LivePlaylistTrackViewModel()
            {
                Id            = votedTrack.Id,
                Track         = votedTrack.Track,
                Score         = 1,
                PersonalScore = 1
            });
            livePlaylistTracks.Add(new LivePlaylistTrackViewModel()
            {
                Id            = notVotedTrack.Id,
                Track         = notVotedTrack.Track,
                Score         = 0,
                PersonalScore = 0
            });
            playlistControllerWithAuthenticatedUser
            .Calling(p => p.getLivePlaylist(playlist.Id))
            .ShouldReturn()
            .Ok()
            .WithResponseModel(new LivePlaylistViewModel()
            {
                Id                  = playlist.Id,
                PlaylistTracks      = livePlaylistTracks,
                Active              = playlist.Active,
                ChatComments        = playlist.ChatComments,
                Comments            = playlist.Comments,
                CreatedById         = playlist.CreatedById,
                Description         = playlist.Description,
                ImageUrl            = playlist.ImageUrl,
                Key                 = playlist.Key,
                MaximumVotesPerUser = playlist.MaximumVotesPerUser,
                PlaylistMasterId    = playlist.PlaylistMasterId,
                Name                = playlist.Name
            })
            .Passing(lp => lp.PlaylistTracks.First().Id == votedTrack.Id);
        }