/// <summary> /// Copy a playlist. Useful for sharing. /// </summary> /// <param name="id">The playlist ID to copy</param> /// <returns>A new playlist with a new ID which has been saved.</returns> public Playlist CopyAndSave(Guid id) { Playlist copiedPlaylist; try { Playlist playlistToCopy = PlaylistDao.Get(id); if (playlistToCopy == null) { string errorMessage = string.Format("No playlist found with id: {0}", id); throw new ApplicationException(errorMessage); } copiedPlaylist = new Playlist(playlistToCopy); DoSave(copiedPlaylist); } catch (Exception exception) { Logger.Error(exception); throw; } return(copiedPlaylist); }
public void Update(Playlist playlist) { try { NHibernateSessionManager.Instance.BeginTransaction(); playlist.ValidateAndThrow(); Playlist knownPlaylist = PlaylistDao.Get(playlist.Id); if (knownPlaylist == null) { PlaylistDao.Update(playlist); } else { PlaylistDao.Merge(playlist); } NHibernateSessionManager.Instance.CommitTransaction(); } catch (Exception exception) { Logger.Error(exception); NHibernateSessionManager.Instance.RollbackTransaction(); throw; } }
public void DeletePlaylist() { // Create a new Playlist and write it to the database. string title = string.Format("New Playlist {0:D4}", User.Playlists.Count); var playlist = new Playlist(title); User.AddPlaylist(playlist); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); PlaylistManager.Save(playlist); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); // Now delete the created Playlist and ensure it is removed. PlaylistManager.Delete(playlist.Id); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); Playlist deletedPlaylist = PlaylistDao.Get(playlist.Id); bool objectNotFoundExceptionEncountered = false; try { // Evaluating a lazyily-loaded entity which isn't in the database will throw an ONF exception. Assert.IsNull(deletedPlaylist); } catch (ObjectNotFoundException) { objectNotFoundExceptionEncountered = true; } Assert.IsTrue(objectNotFoundExceptionEncountered); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); }
public void DeletePlaylist() { // Create a new Playlist and write it to the database. string title = string.Format("New Playlist {0:D4}", Folder.Playlists.Count); var playlist = new Playlist(title); Folder.AddPlaylist(playlist); PlaylistManager.Save(playlist); // Now delete the created Playlist and ensure it is removed. PlaylistManager.Delete(playlist.Id); // Remove entity from NHibernate cache to force DB query to ensure actually created. NHibernateSessionManager.Instance.Clear(); Playlist deletedPlaylist = PlaylistDao.Get(playlist.Id); bool objectNotFoundExceptionEncountered = false; try { // Evaluating a lazyily-loaded entity which isn't in the database will throw an ONF exception. Assert.IsNull(deletedPlaylist); } catch (ObjectNotFoundException) { objectNotFoundExceptionEncountered = true; } Assert.IsTrue(objectNotFoundExceptionEncountered); }
public ShareCode GetShareCode(ShareableEntityType entityType, Guid entityId) { // TODO: Support sharing other entities. if (entityType != ShareableEntityType.Playlist) { throw new NotSupportedException("Only Playlist entityType can be shared currently."); } ShareCode shareCode; try { Playlist playlistToCopy = PlaylistDao.Get(entityId); if (playlistToCopy == null) { string errorMessage = string.Format("No playlist found with id: {0}", entityId); throw new ApplicationException(errorMessage); } var shareablePlaylistCopy = new Playlist(playlistToCopy); PlaylistManager.Save(shareablePlaylistCopy); shareCode = new ShareCode(shareablePlaylistCopy); Save(shareCode); } catch (Exception exception) { Logger.Error(exception); throw; } return(shareCode); }
public void UpdateTitle(Guid playlistId, string title) { try { Playlist playlist = PlaylistDao.Get(playlistId); playlist.Title = title; PlaylistDao.Update(playlist); } catch (Exception exception) { Logger.Error(exception); throw; } }
public void Delete(Guid id) { try { Playlist playlist = PlaylistDao.Get(id); playlist.User.RemovePlaylist(playlist); PlaylistDao.Delete(playlist); } catch (Exception exception) { Logger.Error(exception); throw; } }
public void AddItem_NoItemsInPlaylist_FirstItemIdSet() { Playlist playlist = Folder.CreateAndAddPlaylist(); PlaylistManager.Save(playlist); PlaylistItem playlistItem = Helpers.CreateItemInPlaylist(playlist); // Remove entity from NHibernate cache to force DB query to ensure actually created. NHibernateSessionManager.Instance.Clear(); Playlist playlistFromDatabase = PlaylistDao.Get(playlist.Id); Assert.AreEqual(playlistFromDatabase.FirstItem, playlistItem); }
public Playlist Get(Guid id) { Playlist playlist; try { playlist = PlaylistDao.Get(id); } catch (Exception exception) { Logger.Error(exception); throw; } return(playlist); }
public void UpdateFirstItem(Guid playlistId, Guid firstItemId) { try { NHibernateSessionManager.Instance.BeginTransaction(); Playlist playlist = PlaylistDao.Get(playlistId); playlist.FirstItem = PlaylistItemDao.Get(firstItemId); PlaylistDao.Update(playlist); NHibernateSessionManager.Instance.CommitTransaction(); } catch (Exception exception) { Logger.Error(exception); NHibernateSessionManager.Instance.RollbackTransaction(); throw; } }
public void UpdateTitle(Guid playlistId, string title) { try { NHibernateSessionManager.Instance.BeginTransaction(); Playlist playlist = PlaylistDao.Get(playlistId); playlist.Title = title; PlaylistDao.Update(playlist); NHibernateSessionManager.Instance.CommitTransaction(); } catch (Exception exception) { Logger.Error(exception); NHibernateSessionManager.Instance.RollbackTransaction(); throw; } }
public void Updates() { Playlist playlist = Folder.CreateAndAddPlaylist(); PlaylistManager.Save(playlist); PlaylistManager.UpdateTitle(playlist.Id, "Existing Playlist 001"); // Remove entity from NHibernate cache to force DB query to ensure actually created. NHibernateSessionManager.Instance.Clear(); Playlist playlistFromDatabase = PlaylistDao.Get(playlist.Id); // Test that the product was successfully inserted Assert.IsNotNull(playlistFromDatabase); Assert.AreEqual(playlist.Title, playlistFromDatabase.Title); }
public void Delete(Guid id) { try { NHibernateSessionManager.Instance.BeginTransaction(); Playlist playlist = PlaylistDao.Get(id); playlist.Folder.RemovePlaylist(playlist); PlaylistDao.Delete(playlist); NHibernateSessionManager.Instance.CommitTransaction(); } catch (Exception exception) { Logger.Error(exception); NHibernateSessionManager.Instance.RollbackTransaction(); throw; } }
public void Updates() { Playlist playlist = User.CreateAndAddPlaylist(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); PlaylistManager.Save(playlist); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); PlaylistManager.UpdateTitle(playlist.Id, "Existing Playlist 001"); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction(); Playlist playlistFromDatabase = PlaylistDao.Get(playlist.Id); // Test that the product was successfully inserted Assert.IsNotNull(playlistFromDatabase); // Sessions should be isolated -- before and after should be different here. Assert.AreNotEqual(playlist.Title, playlistFromDatabase.Title); NHibernateSessionManager.Instance.CommitTransactionAndCloseSession(); }
public void Update(Playlist playlist) { try { playlist.ValidateAndThrow(); Playlist knownPlaylist = PlaylistDao.Get(playlist.Id); if (knownPlaylist == null) { PlaylistDao.Update(playlist); } else { PlaylistDao.Merge(playlist); } } catch (Exception exception) { Logger.Error(exception); throw; } }
public void Update(Playlist playlist) { try { playlist.ValidateAndThrow(); // TODO: Is this necessary still? Seems odd to me. Playlist knownPlaylist = PlaylistDao.Get(playlist.Id); if (knownPlaylist == null) { PlaylistDao.Update(playlist); } else { PlaylistDao.Merge(playlist); } } catch (Exception exception) { Logger.Error(exception); throw; } }