예제 #1
0
        public ActionResult Update(PlaylistDto playlistDto)
        {
            Playlist playlist = Playlist.Create(playlistDto);
            PlaylistManager.Update(playlist);

            PlaylistDto updatedPlaylistDto = PlaylistDto.Create(playlist);
            return new JsonDataContractActionResult(updatedPlaylistDto);
        }
예제 #2
0
        /// <summary>
        ///     Generate a PlaylistDto which has the User as its parent.
        /// </summary>
        /// <returns></returns>
        public PlaylistDto CreatePlaylistDto(Guid userIdOverride)
        {
            var playlistDto = new PlaylistDto
            {
                UserId = userIdOverride
            };

            return playlistDto;
        }
예제 #3
0
        /// <summary>
        ///     Generate a PlaylistDto which has the User as its parent.
        /// </summary>
        /// <returns></returns>
        public static PlaylistDto CreatePlaylistDto(Guid userIdOverride)
        {
            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();

            var playlistDto = new PlaylistDto
                {
                    UserId = userIdOverride
                };

            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();

            return playlistDto;
        }
예제 #4
0
        public ActionResult Create(PlaylistDto playlistDto)
        {
            Playlist playlist = Playlist.Create(playlistDto);
            playlist.Folder.AddPlaylist(playlist);

            //  Make sure the playlist has been setup properly before it is cascade-saved through the Folder.
            playlist.ValidateAndThrow();

            PlaylistManager.Save(playlist);

            PlaylistDto savedPlaylistDto = PlaylistDto.Create(playlist);

            return new JsonDataContractActionResult(savedPlaylistDto);
        }
예제 #5
0
        public static Playlist Create(PlaylistDto playlistDto)
        {
            Playlist playlist = Mapper.Map<PlaylistDto, Playlist>(playlistDto);

            //  TODO: I could probably leverage backbone's CID property to have the items know of their playlist.
            //  If an unsaved playlist comes from the client with items already in it, the items will not know their playlist's ID.
            //  So, re-map to the playlist as appropriate.

            List<PlaylistItem> improperlyAddedItems = playlist.Items.Where(i => i.Playlist == null).ToList();
            improperlyAddedItems.ForEach(i => playlist.Items.Remove(i));

            playlist.AddItems(improperlyAddedItems);

            return playlist;
        }
예제 #6
0
        /// <summary>
        ///     Create a new Folder, save it to the DB, then generate a PlaylistDto which has the
        ///     Folder as its parent. Creates a folder for the Playlist if no folderId provided.
        /// </summary>
        /// <returns></returns>
        public static PlaylistDto CreatePlaylistDto(Guid folderIdOverride = default(Guid))
        {
            if (folderIdOverride == default(Guid))
            {
                Folder folder = new Folder();
                FolderManager.Save(folder);
                folderIdOverride = folder.Id;
                
                //  Ensure folder is lazy-loaded by evicting to make sure this helper method doesn't have side-effects.
                NHibernateSessionManager.Instance.Evict(folder);
            }

            var playlistDto = new PlaylistDto
                {
                    FolderId = folderIdOverride
                };

            return playlistDto;
        }
예제 #7
0
        public static Playlist Create(PlaylistDto playlistDto, IUserManager userManager, IPlaylistManager playlistManager)
        {
            Playlist playlist = new Playlist
                {
                    Id = playlistDto.Id,
                    Items = PlaylistItem.Create(playlistDto.Items, playlistManager),
                    Sequence = playlistDto.Sequence,
                    Title = playlistDto.Title,
                    User = userManager.Get(playlistDto.UserId)
                };

            //  TODO: This seems unnecessary...
            //  TODO: I could probably leverage backbone's CID property to have the items know of their playlist. Or maybe I should just enforce adding client-side before saving?
            //  If an unsaved playlist comes from the client with items already in it, the items will not know their playlist's ID.
            //  So, re-map to the playlist as appropriate.
            List<PlaylistItem> improperlyAddedItems = playlist.Items.Where(i => i.Playlist == null).ToList();
            improperlyAddedItems.ForEach(i => playlist.Items.Remove(i));
            playlist.AddItems(improperlyAddedItems);

            return playlist;
        }
예제 #8
0
        public JsonResult Create(PlaylistDto playlistDto)
        {
            PlaylistDto savedPlaylistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = Playlist.Create(playlistDto, UserManager, PlaylistManager);
                playlist.User.AddPlaylist(playlist);

                //  Make sure the playlist has been setup properly before it is cascade-saved through the User.
                playlist.ValidateAndThrow();

                PlaylistManager.Save(playlist);

                savedPlaylistDto = PlaylistDto.Create(playlist);

                transaction.Commit();
            }

            return Json(savedPlaylistDto);
        }
예제 #9
0
        public static PlaylistDto Create(Playlist playlist)
        {
            PlaylistDto playlistDto = Mapper.Map <Playlist, PlaylistDto>(playlist);

            return(playlistDto);
        }
예제 #10
0
        public JsonResult Update(PlaylistDto playlistDto)
        {
            PlaylistDto updatedPlaylistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = Playlist.Create(playlistDto, UserManager, PlaylistManager);
                PlaylistManager.Update(playlist);

                updatedPlaylistDto = PlaylistDto.Create(playlist);

                transaction.Commit();
            }

            return Json(updatedPlaylistDto);
        }
        public ActionResult Update(PlaylistDto playlistDto)
        {
            Playlist playlist = Playlist.Create(playlistDto);
            PlaylistManager.Update(playlist);

            PlaylistDto updatedPlaylistDto = PlaylistDto.Create(playlist);
            return new JsonServiceStackResult(updatedPlaylistDto);
        }