public void removeFromPlayqueue(int itemId) { using (var db = new PlaylistDBContext()) { PlaylistItem itemToRemove = db.Playlist.FirstOrDefault(item => item.ItemId == itemId); if (itemToRemove != null) { PodcastEpisodeModel episode = null; using (var episodeDb = new PodcastSqlModel()) { episode = episodeDb.episodeForPlaylistItem(itemToRemove); if (episode != null) { if (episode.isListened()) { episode.markAsListened(episodeDb.settings().IsAutoDelete); } } else { Debug.WriteLine("Warning: Could not get episode for item id: " + itemToRemove.ItemId); } } db.Playlist.DeleteOnSubmit(itemToRemove); db.SubmitChanges(); App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>(); } } }
public void sortPlaylist(int sortOrder) { using (var playlistDB = new PlaylistDBContext()) { if (playlistDB.Playlist.Count() <= 1) { return; } PodcastSqlModel sqlContext = new PodcastSqlModel(); IEnumerable <PlaylistItem> newSortOrderQuery = null; List <PlaylistItem> newSortOrder = new List <PlaylistItem>(); var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext), item => item.EpisodeId, episode => episode.EpisodeId, (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode }); switch (sortOrder) { // Oldest first case 0: newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; // Newest first. case 1: newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; } int i = 0; foreach (PlaylistItem item in newSortOrderQuery) { PlaylistItem newItem = item; newItem.OrderNumber = i++; newSortOrder.Add(newItem); } playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist); playlistDB.Playlist.InsertAllOnSubmit(newSortOrder); playlistDB.SubmitChanges(); } Deployment.Current.Dispatcher.BeginInvoke(() => { App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>(); }); }
private void workerSortPlaylist(object sender, DoWorkEventArgs args) { int selectedSortOrderIndex = (int)args.Argument; using (var playlistDB = new PlaylistDBContext()) { if (playlistDB.Playlist.Count() <= 1) { return; } PodcastSqlModel sqlContext = new PodcastSqlModel(); IEnumerable <PlaylistItem> newSortOrderQuery = null; List <PlaylistItem> newSortOrder = new List <PlaylistItem>(); var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext), item => item.EpisodeId, episode => episode.EpisodeId, (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode }); switch (selectedSortOrderIndex) { // Oldest first case 0: newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; // Newest first. case 1: newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; } int i = 0; foreach (PlaylistItem item in newSortOrderQuery) { PlaylistItem newItem = item; newItem.OrderNumber = i++; newSortOrder.Add(newItem); } playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist); playlistDB.Playlist.InsertAllOnSubmit(newSortOrder); playlistDB.SubmitChanges(); } }
public void addToPlayqueue(PodcastEpisodeModel episode, bool showNotification = true) { using (var db = new PlaylistDBContext()) { addToPlayqueue(episode, db); db.SubmitChanges(); } using (var db = new PodcastSqlModel()) { sortPlaylist(db.settings().PlaylistSortOrder); } if (showNotification) { showAddedNotification(1); } }
public void addToPlayqueue(Collection <PodcastEpisodeModel> episodes) { using (var db = new PlaylistDBContext()) { foreach (PodcastEpisodeModel e in episodes) { addToPlayqueue(e, db); } db.SubmitChanges(); } using (var db = new PodcastSqlModel()) { sortPlaylist(db.settings().PlaylistSortOrder); } App.mainViewModels.PlayQueue = new ObservableCollection <PlaylistItem>(); showAddedNotification(episodes.Count); }
private void workerSortPlaylist(object sender, DoWorkEventArgs args) { int selectedSortOrderIndex = (int)args.Argument; using (var playlistDB = new PlaylistDBContext()) { if (playlistDB.Playlist.Count() <= 1) { return; } PodcastSqlModel sqlContext = new PodcastSqlModel(); IEnumerable<PlaylistItem> newSortOrderQuery = null; List<PlaylistItem> newSortOrder = new List<PlaylistItem>(); var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext), item => item.EpisodeId, episode => episode.EpisodeId, (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode }); switch (selectedSortOrderIndex) { // Oldest first case 0: newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; // Newest first. case 1: newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; } int i = 0; foreach (PlaylistItem item in newSortOrderQuery) { PlaylistItem newItem = item; newItem.OrderNumber = i++; newSortOrder.Add(newItem); } playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist); playlistDB.Playlist.InsertAllOnSubmit(newSortOrder); playlistDB.SubmitChanges(); } }
public void removeFromPlayqueue(int itemId) { using (var db = new PlaylistDBContext()) { PlaylistItem itemToRemove = db.Playlist.FirstOrDefault(item => item.ItemId == itemId); if (itemToRemove != null) { PodcastEpisodeModel episode = null; using (var episodeDb = new PodcastSqlModel()) { episode = episodeDb.episodeForPlaylistItem(itemToRemove); if (episode != null) { if (episode.isListened()) { episode.markAsListened(episodeDb.settings().IsAutoDelete); } } else { Debug.WriteLine("Warning: Could not get episode for item id: " + itemToRemove.ItemId); } } db.Playlist.DeleteOnSubmit(itemToRemove); db.SubmitChanges(); App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>(); } } }
public void addToPlayqueue(PodcastEpisodeModel episode, bool showNotification = true) { using (var db = new PlaylistDBContext()) { addToPlayqueue(episode, db); db.SubmitChanges(); } using (var db = new PodcastSqlModel()) { sortPlaylist(db.settings().PlaylistSortOrder); } if (showNotification) { showAddedNotification(1); } }
public void addToPlayqueue(Collection<PodcastEpisodeModel> episodes) { using (var db = new PlaylistDBContext()) { foreach (PodcastEpisodeModel e in episodes) { addToPlayqueue(e, db); } db.SubmitChanges(); } using (var db = new PodcastSqlModel()) { sortPlaylist(db.settings().PlaylistSortOrder); } App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>(); showAddedNotification(episodes.Count); }
public void sortPlaylist(int sortOrder) { using (var playlistDB = new PlaylistDBContext()) { if (playlistDB.Playlist.Count() <= 1) { return; } PodcastSqlModel sqlContext = new PodcastSqlModel(); IEnumerable<PlaylistItem> newSortOrderQuery = null; List<PlaylistItem> newSortOrder = new List<PlaylistItem>(); var query = playlistDB.Playlist.AsEnumerable().Join(episodes(sqlContext), item => item.EpisodeId, episode => episode.EpisodeId, (item, episode) => new { PlaylistItem = item, PodcastEpisodeModel = episode }); switch (sortOrder) { // Oldest first case 0: newSortOrderQuery = query.OrderBy(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; // Newest first. case 1: newSortOrderQuery = query.OrderByDescending(newPlaylistItem => newPlaylistItem.PodcastEpisodeModel.EpisodePublished) .Select(newPlaylistItem => newPlaylistItem.PlaylistItem).AsEnumerable(); break; } int i = 0; foreach (PlaylistItem item in newSortOrderQuery) { PlaylistItem newItem = item; newItem.OrderNumber = i++; newSortOrder.Add(newItem); } playlistDB.Playlist.DeleteAllOnSubmit(playlistDB.Playlist); playlistDB.Playlist.InsertAllOnSubmit(newSortOrder); playlistDB.SubmitChanges(); } Deployment.Current.Dispatcher.BeginInvoke(() => { App.mainViewModels.PlayQueue = new ObservableCollection<PlaylistItem>(); }); }