public async Task <bool> LoadNew(int id) { var name = PlaylistStatic.RetrieveNameById(id); if (name == null) { return(false); } Name = name; Id = id; List <PlaylistItem> items = await PlaylistItemStatic.RetrievePlaylistItemsByPlaylistId(id); foreach (var item in items) { Add(item); } if (Shuffle) { GenerateRandomIndexes(); } if (Items.Count() > 0) { HasItems = true; if (SelectedIndex == -1) { SelectedIndex = 0; } } else { HasItems = false; } return(true); }
public static int Save(Playlist playlist, string name) { using (SqliteConnection db = OnelyDB.Open()) { SqliteCommand command; if (playlist.Name == null) { // Is name taken? command = new SqliteCommand { Connection = db, CommandText = "SELECT id FROM playlists WHERE name=@Name" }; command.Parameters.AddWithValue("@Name", name); var res = OnelyDB.ExecuteReader(command); if (res.HasRows) { return(-1); } command = new SqliteCommand { Connection = db, CommandText = "INSERT INTO playlists(name) VALUES (@Name)" }; command.Parameters.AddWithValue("@Name", name); OnelyDB.ExecuteReader(command); playlist.Id = OnelyDB.GetLastInsertId(db); playlist.Name = name; } else { if (name != playlist.Name) { command = new SqliteCommand { Connection = db, CommandText = "UPDATE playlists SET name=@Name WHERE id=@ID" }; command.Parameters.AddWithValue("@Name", name); command.Parameters.AddWithValue("@ID", playlist.Id); OnelyDB.ExecuteReader(command); playlist.Name = name; } PlaylistItemStatic.DeleteBasedOnPlaylistId(playlist.Id, db); } int count = 0; foreach (var item in playlist.Items) { PlaylistItemStatic.Save(item, playlist.Id, count, db); count++; } OnelyDB.Close(db); return(playlist.Id); } }
// Loading files public async Task <bool> LoadFiles(IEnumerable <StorageFile> audioFiles, IEnumerable <StorageFile> imageFiles) { AlbumCover cover; StorageFile imageFile = imageFiles.FirstOrDefault(); if (imageFile != null) { cover = GetExistingAlbumCover(imageFile.Path); if (cover == null) { cover = await AlbumCover.FromStorageFile(imageFile); if (cover != null) { AlbumCovers.Add(cover); string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(imageFile); } } } else { cover = null; } foreach (var file in audioFiles) { var item = await PlaylistItemStatic.LoadFromFile(file); Add(item); string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file); if (cover != null) { item.MainCover = cover; } } if (Shuffle) { GenerateRandomIndexes(); } if (Items.Count() > 0) { HasItems = true; } else { HasItems = false; } if (SelectedIndex == -1) { SelectedIndex = 0; } return(true); }
public static void DeletePlaylistById(int id) { using (SqliteConnection db = OnelyDB.Open()) { PlaylistItemStatic.DeleteBasedOnPlaylistId(id, db); SqliteCommand command = new SqliteCommand { Connection = db, CommandText = "DELETE FROM playlists WHERE id=@ID" }; command.Parameters.AddWithValue("@ID", id); OnelyDB.ExecuteReader(command); OnelyDB.Close(db); } }