示例#1
0
        public static void SaveNewPlayList(PlaylistModel model)
        {
            if (CurrentUser == null)
            {
                return;
            }
            string name = model.Name;

            using (var conn = ConnectionFactory())
            {
                var adapter = new BeautifulMusicDataSetTableAdapters.PlaylistTableAdapter {
                    Connection = conn
                };
                List <TrackModel> tracks = new List <TrackModel>();
                var listId = adapter.GetPlayListByName(name);
                int.TryParse(listId + "", out int id);
                if (id > 0)
                {
                    var trackTableAdapter = new BeautifulMusicDataSetTableAdapters.TrackTableAdapter
                    {
                        Connection = conn
                    };
                    trackTableAdapter.FillByPlayList(MusicDataSet.Track, id);
                    tracks = MusicDataSet.Track.DataTableToList <TrackModel>();
                }
                else
                {
                    var row = MusicDataSet.Playlist.NewPlaylistRow();
                    row.Name   = name;
                    row.UserId = CurrentUser.Id;
                    MusicDataSet.Playlist.AddPlaylistRow(row);
                    adapter.Update(row);
                    id = row.Id;
                }
                model.Id = id;
                TrackModels.Select(x => x.Id)
                .Except(tracks.Select(x => x.Id))
                .Distinct()
                .ToList()
                .ForEach(
                    x =>
                {
                    var row        = MusicDataSet.PlaylistTrack.NewPlaylistTrackRow();
                    row.PlaylistId = id;
                    row.TrackId    = x;
                    MusicDataSet.PlaylistTrack.AddPlaylistTrackRow(row);
                });
                var playlistTrackTableAdapter = new BeautifulMusicDataSetTableAdapters.PlaylistTrackTableAdapter
                {
                    Connection = conn
                };
                playlistTrackTableAdapter.Update(MusicDataSet.PlaylistTrack);
            }
        }
 /// <summary>
 ///     Gets the tracks in the play-list
 /// </summary>
 /// <returns>The tracks in the play-list</returns>
 public List <Track> GetTracks()
 {
     return(TrackModels.Select(GetLibraryTrack).ToList());
 }
        private void SaveWorkingPlaylist()
        {
            var playlistFiles = TrackModels.Select(x => x.Description).ToList();

            SerializationHelper <List <string> > .ToXmlFile(playlistFiles, WorkingPlaylistFilename);
        }