예제 #1
0
 public static void DeletePlayList(int id)
 {
     using (var conn = ConnectionFactory())
     {
         var adapter = new BeautifulMusicDataSetTableAdapters.PlaylistTableAdapter {
             Connection = conn
         };
         adapter.Delete(id);
     }
 }
예제 #2
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);
            }
        }
예제 #3
0
        public static ObservableCollection <PlaylistModel> GetPlayLists()
        {
            var models = new ObservableCollection <PlaylistModel>();

            if (CurrentUser == null)
            {
                return(models);
            }
            using (var conn = ConnectionFactory())
            {
                var adapter = new BeautifulMusicDataSetTableAdapters.PlaylistTableAdapter {
                    Connection = conn
                };
                adapter.FillByUser(MusicDataSet.Playlist, CurrentUser.Id);
                MusicDataSet.Playlist.DataTableToList <PlaylistModel>().ForEach(x => models.Add(x));
                return(models);
            }
        }