예제 #1
0
        /// <summary>
        /// Updates a MediaTrack
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>True if the the update is successful.</returns>
        public static bool Update(MediaTrack mediaTrack)
        {
            //Get the current persisted MediaTrack
            MediaTrack currentTrack = Get(mediaTrack.TrackId);

            //Update the MediaTrack
            bool isUpdated = DBMediaTrack.Update(
                mediaTrack.TrackId,
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid);

            //If the MediaTrack successfully updated, update the associated MediaFiles.
            if (isUpdated)
            {
                //Remove any MediaFiles that no longer exist.
                foreach (MediaFile currentFile in currentTrack.MediaFiles)
                {
                    bool matchFound = false;
                    foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                    {
                        if (currentFile.FileId == updatedFile.FileId)
                        {
                            matchFound = true;
                            break;
                        }
                    }

                    if (!matchFound)
                    {
                        MediaFile.Remove(currentFile);
                    }
                }

                //Add any MediaFiles that have not been persisted yet.
                foreach (MediaFile updatedFile in mediaTrack.MediaFiles)
                {
                    if (updatedFile.FileId <= 0)
                    {
                        updatedFile.FileId = MediaFile.Add(updatedFile);
                    }
                }
            }

            return(isUpdated);
        }
예제 #2
0
        /// <summary>
        /// Adds a MediaTrack.
        /// </summary>
        /// <param name="mediaTrack">The MediaTrack.</param>
        /// <returns>The ID of the MediaTrack.</returns>
        public static int Add(MediaTrack mediaTrack)
        {
            //Insert the MediaTrack.
            int trackId = DBMediaTrack.Insert(
                mediaTrack.PlayerId,
                mediaTrack.TrackType.ToString(),
                mediaTrack.TrackOrder,
                mediaTrack.Name,
                mediaTrack.Artist,
                mediaTrack.UserGuid
                );

            mediaTrack.trackId = trackId;

            //Insert each of MediaTrack's MediaFiles.
            foreach (MediaFile file in mediaTrack.MediaFiles)
            {
                file.TrackId = trackId;
                MediaFile.Add(file);
            }

            return(trackId);
        }