Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Downvote(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));
        }
Ejemplo n.º 3
0
        public ActionResult UnVote(long id)
        {
            var user = userManager.ReadUser(User != null ? User.Identity.Name : testName);

            playlistManager.DeleteVote(id, user.Id);

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