Ejemplo n.º 1
0
        /// <summary>
        /// Remove a song from a playlist.
        /// </summary>
        /// <param name="songID">The SongID</param>
        /// <param name="playListID">The PlaylistID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileRemoveSongFromPlaylist(int songID, int playListID, long userKey)
        {
            int mobileID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Make sure the client isn't already logged out.
                r = MobileCheckStatus(mobileID, "!0", db);
                if (r.error)
                    return r;

                // Get the current songs in the playlist.
                List<Song> songs;
                r = db.MobileGetSongsFromPlaylist(playListID, mobileID, out songs);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Find the song to remove and remove it.
                for (int i = 0; i < songs.Count; i++)
                {
                    if (songs[i].ID == songID)
                    {
                        songs.RemoveAt(i);
                        r = db.MobileSetPlaylistSongs(playListID, mobileID, songs);
                        if (r.error)
                            return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                        return r;
                    }
                }

                // If we didn't find the song to remove.
                r.error = true;
                r.message = "Could not find the song in the playlist";
                return r;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a song to a playlist.
        /// </summary>
        /// <param name="songID">The songID</param>
        /// <param name="playListID">The PlaylistID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileAddSongToPlaylist(int songID, int playListID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Get the venue information from the playlist in DB.
                r = db.MobileGetVenueFromPlaylist(playListID, mobileID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!int.TryParse(r.message.Trim(), out venueID))
                {
                    r.setErMsgStk(true, "Could not figure out Venue from DB", Environment.StackTrace);
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.setErMsg(true, Messages.MSG_SONG_NOT_FOUND);
                    return r;
                }

                // Object to represent the song to add.
                Song song = new Song();
                song.ID = songID;

                // Get the current songs in the playlist.
                List<Song> songs;
                r = db.MobileGetSongsFromPlaylist(playListID, mobileID, out songs);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Check to see if the song already exists.
                foreach (Song s in songs)
                {
                    if (s.ID == song.ID)
                    {
                        r.setErMsg(true, Messages.ERR_PLYLST_DUP_SONG);
                        return r;
                    }
                }

                // Otherwise, add this to the playlist.
                songs.Add(song);
                r = db.MobileSetPlaylistSongs(playListID, mobileID, songs);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                return r;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a song to a playlist.
        /// </summary>
        /// <param name="songID">The songID</param>
        /// <param name="playListID">The PlaylistID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileAddSongToPlaylist(int songID, int playListID, long userKey)
        {
            int venueID = -1;
            int songExists;
            int mobileID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                Response r = db.OpenConnection();
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Make sure the client isn't already logged out.
                r = MobileCheckStatus(mobileID, "!0", db);
                if (r.error)
                    return r;

                // Get the venue information from the playlist in DB.
                r = db.MobileGetVenueFromPlaylist(playListID, mobileID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                if (!int.TryParse(r.message.Trim(), out venueID))
                {
                    r.error = true;
                    r.message = "Could not figure out Venue from DB";
                    return r;
                }

                // Check to see if song exists.
                r = db.SongExists(venueID, songID);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                if (!int.TryParse(r.message.Trim(), out songExists))
                {
                    r.error = true;
                    r.message = "Could not find song in venue's library.";
                    return r;
                }

                // Object to represent the song to add.
                Song song = new Song();
                song.ID = songID;

                // Get the current songs in the playlist.
                List<Song> songs;
                r = db.MobileGetSongsFromPlaylist(playListID, mobileID, out songs);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);

                // Check to see if the song already exists.
                foreach (Song s in songs)
                {
                    if (s.ID == song.ID)
                    {
                        r.error = true;
                        r.message = "You already have that song in this playlist";
                        return r;
                    }
                }

                // Otherwise, add this to the playlist.
                songs.Add(song);
                r = db.MobileSetPlaylistSongs(playListID, mobileID, songs);
                if (r.error)
                    return (Response)Common.LogError(r.message, Environment.StackTrace, r, 0);
                return r;
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Remove a song from a playlist.
        /// </summary>
        /// <param name="songID">The SongID</param>
        /// <param name="playListID">The PlaylistID</param>
        /// <param name="userKey">client mobile key.</param>
        /// <returns>The outcome of the opearation.</returns>
        public Response MobileRemoveSongFromPlaylist(int songID, int playListID, long userKey)
        {
            int mobileID;
            using (DatabaseConnectivity db = new DatabaseConnectivity())
            {
                // Try to establish a database connection
                ExpResponse r = db.OpenConnection();
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Convert the userKey to MobileID
                r = MobileKeyToID(userKey, out mobileID, db);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Make sure the client isn't already logged out.
                bool validStatus;
                r = MobileCheckStatus(mobileID, "!0", db, out validStatus);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                if (!validStatus)
                {
                    r.setErMsg(true, Messages.ERR_STATUS_IS_NOT_IN);
                    return r;
                }

                // Get the current songs in the playlist.
                List<Song> songs;
                r = db.MobileGetSongsFromPlaylist(playListID, mobileID, out songs);
                if (r.error)
                    return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);

                // Find the song to remove and remove it.
                for (int i = 0; i < songs.Count; i++)
                {
                    if (songs[i].ID == songID)
                    {
                        songs.RemoveAt(i);
                        r = db.MobileSetPlaylistSongs(playListID, mobileID, songs);
                        if (r.error)
                            return Common.LogErrorRetNewMsg(r, Messages.ERR_SERVER, Common.LogFile.Mobile);
                        return r;
                    }
                }

                // If we didn't find the song to remove.
                r.setErMsg(true, Messages.MSG_SONG_NOT_FOUND);
                return r;
            }
        }