예제 #1
0
        public static object UpdateNowPlayingTrack(string spotifyUri)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                Track nowPlaying = db.Tracks.FirstOrDefault(r => r.SpotifyUri == spotifyUri);
                if (nowPlaying != null)
                {
                    // update now playing track (replacement for last fm scrobbler)
                    nowPlaying.LastPlayed = DateTime.Now;

                    // Wipe any request date to make sure it goes to back of queue
                    nowPlaying.RequestDate = null;

                    // increment play counter
                    nowPlaying.PlayCount++;

                    db.SaveChanges();

                    // return the track to be sent to the users
                    return(FormatTrack(nowPlaying));
                }
                else
                {
                    throw new NotSupportedException("The track was not in the play queue");
                }
            }
        }
예제 #2
0
        public static void SaveTrackVote(long userId, int trackId, TrackVoteType type)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                // check user exists in db
                UserManager.GetOrCreateUser(db, userId);

                // add, remove or update track like
                var existingLike = db.TrackLikes.SingleOrDefault(tl => tl.TrackID == trackId && tl.UserID == userId);
                if (existingLike == null)
                {
                    // add new
                    existingLike         = new e3Radio.Data.TrackLike();
                    existingLike.TrackID = trackId;
                    existingLike.UserID  = userId;
                    db.TrackLikes.Add(existingLike);
                }
                if (type == TrackVoteType.unvote)
                {
                    // delete the love/hate entry
                    db.TrackLikes.Remove(existingLike);
                }
                else
                {
                    // add or update
                    existingLike.IsLike    = (type == TrackVoteType.love);
                    existingLike.DateLiked = DateTime.Now;
                }
                db.SaveChanges();
            }
        }
예제 #3
0
        public static object RequestTrack(string spotifyUri, long userId)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                // check user exists in db
                UserManager.GetOrCreateUser(db, userId);

                // find existing track, if it has been played before, or add
                Track track = e3Radio.Data.Spotify.GetOrCreateTrackBySpotifyUri(db, spotifyUri);
                if (track == null)
                {
                    throw new Exception("Failed to find Spotify Track");
                }

                // mark it as requested by this user and now, this makes it play sooner
                track.RequestDate   = DateTime.Now;
                track.RequestUserID = userId;

                db.SaveChanges();

                // Convert track into list of track info
                return(FormatTrack(track));
            }
        }
예제 #4
0
        public static object UpdateNowPlayingTrack(string spotifyUri)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                Track nowPlaying = db.Tracks.FirstOrDefault(r => r.SpotifyUri == spotifyUri);
                if (nowPlaying != null)
                {
                    // update now playing track (replacement for last fm scrobbler)
                    nowPlaying.LastPlayed = DateTime.Now;

                    // Wipe any request date to make sure it goes to back of queue
                    nowPlaying.RequestDate = null;

                    // increment play counter
                    nowPlaying.PlayCount++;

                    db.SaveChanges();

                    // return the track to be sent to the users
                    return FormatTrack(nowPlaying);
                }
                else
                {
                    throw new NotSupportedException("The track was not in the play queue");
                }
            }
        }
예제 #5
0
        public static void SaveTrackVote(long userId, int trackId, TrackVoteType type)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                // check user exists in db
                UserManager.GetOrCreateUser(db, userId);

                // add, remove or update track like
                var existingLike = db.TrackLikes.SingleOrDefault(tl => tl.TrackID == trackId && tl.UserID == userId);
                if (existingLike == null)
                {
                    // add new
                    existingLike = new e3Radio.Data.TrackLike();
                    existingLike.TrackID = trackId;
                    existingLike.UserID = userId;
                    db.TrackLikes.Add(existingLike);
                }
                if (type == TrackVoteType.unvote)
                {
                    // delete the love/hate entry
                    db.TrackLikes.Remove(existingLike);
                }
                else
                {
                    // add or update
                    existingLike.IsLike = (type == TrackVoteType.love);
                    existingLike.DateLiked = DateTime.Now;
                }
                db.SaveChanges();
            }
        }
예제 #6
0
        public static object RequestTrack(string spotifyUri, long userId)
        {
            using (var db = new e3Radio.Data.E3RadioEntities())
            {
                // check user exists in db
                UserManager.GetOrCreateUser(db, userId);

                // find existing track, if it has been played before, or add
                Track track = e3Radio.Data.Spotify.GetOrCreateTrackBySpotifyUri(db, spotifyUri);
                if (track == null)
                {
                    throw new Exception("Failed to find Spotify Track");
                }

                // mark it as requested by this user and now, this makes it play sooner
                track.RequestDate = DateTime.Now;
                track.RequestUserID = userId;

                db.SaveChanges();

                // Convert track into list of track info
                return FormatTrack(track);
            }
        }