Example #1
0
 public ActionResult CreatePlAdmin(PlaylistDto playlistDTO)
 {
     try
     {
         var UserId = (UserDTO)Session[CommonConstants.USER_SESSION];
         playlistDTO.UserID = UserId.ID;
         //playlistDTO.UserID = 31;
         if (playlistDTO.FileImage != null)
         {
             playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
             playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
             playlistDTO.FileImage = null;
         }
         else
         {
             playlistDTO.PlaylistImage = "default.png";
         }
         var data = ApiService.CreatePlaylist(playlistDTO);
         if (data != null)
         {
             return(RedirectToAction("ViewAddPlaylist", "Playlist"));
         }
         return(RedirectToAction("ViewAddPlaylist"));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(RedirectToAction("ViewAddPlaylist"));
     }
 }
        /// <summary>
        /// Gets the playlist specified for the user specified.
        /// </summary>
        public PlaylistDto GetPlaylistForUser(string username, string playlistName)
        {
            // Create a new empty playlist object
            var playlist = new PlaylistDto {
                Username = username, PlaylistName = playlistName
            };

            // Read the tracks from the database
            PreparedStatement prepared =
                _session.Prepare("SELECT username, playlist_name, sequence_no, artist, track_name, track_id, genre, track_length_in_seconds " +
                                 "FROM playlist_tracks WHERE username = ? and playlist_name = ?");
            BoundStatement bound   = prepared.Bind(username, playlistName);
            RowSet         results = _session.Execute(bound);

            foreach (Row row in results.GetRows())
            {
                PlaylistTrackDto track = MapRowToPlaylistTrack(row);
                playlist.TrackList.Add(track);

                // Pre-aggregate the playlist length in seconds;
                playlist.PlaylistLengthInSeconds += track.TrackLengthInSeconds;
            }

            return(playlist);
        }
Example #3
0
        public ActionResult Get(Guid id)
        {
            Playlist    playlist    = PlaylistDao.Get(id);
            PlaylistDto playlistDto = PlaylistDto.Create(playlist);

            return(new JsonServiceStackResult(playlistDto));
        }
        /// <summary>
        /// Deletes a track from a playlist by its sequence number.
        /// </summary>
        public void DeleteTrackFromPlaylist(PlaylistDto playlist, long sequenceNumber)
        {
            // Find the track to delete, and delete it from the list

            // Find the track that has a matching sequence number
            int index = playlist.TrackList.FindIndex(track => track.SequenceNumber == sequenceNumber);

            // If the track was not found nothing to do
            if (index < 0)
            {
                return;
            }

            // Get the track to delete, remove it from the playlist's track list
            PlaylistTrackDto playlistTrackToDelete = playlist.TrackList[index];

            playlist.TrackList.RemoveAt(index);

            // Adjust the playlist length
            playlist.PlaylistLengthInSeconds -= playlistTrackToDelete.TrackLengthInSeconds;

            // Remove it from the database
            PreparedStatement prepared = _session.Prepare("DELETE from playlist_tracks where username = ? and playlist_name = ? and sequence_no = ?");
            BoundStatement    bound    = prepared.Bind(playlist.Username, playlist.PlaylistName,
                                                       SequenceToDateTimeOffset(playlistTrackToDelete.SequenceNumber));

            _session.Execute(bound);
        }
Example #5
0
        public PlaylistDto CreateCopyByShareCode(ShareCodeRequestDto shareCodeRequestDto)
        {
            PlaylistDto playlistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                ShareCode shareCode = ShareCodeManager.GetByShortIdAndEntityTitle(shareCodeRequestDto.ShortId, shareCodeRequestDto.UrlFriendlyEntityTitle);

                //  Never return the sharecode's playlist reference. Make a copy of it to give out so people can't modify the original.
                Playlist playlistToCopy = PlaylistManager.Get(shareCode.EntityId);

                User user = UserManager.Get(shareCodeRequestDto.UserId);

                var playlistCopy = new Playlist(playlistToCopy);
                user.AddPlaylist(playlistCopy);

                PlaylistManager.Save(playlistCopy);

                playlistDto = PlaylistDto.Create(playlistCopy);

                transaction.Commit();
            }

            return(playlistDto);
        }
Example #6
0
        public Task PublishEpisode(Episode episode)
        {
            PlaylistDto majedPlaylist = null;
            var         serializer    = new JsonSerializer();
            var         dtoToSave     = EpisodeDto.CreateFromEpisode(episode);

            if (new FileInfo(SaveFileName).Exists)
            {
                using (var fileStream = File.OpenText(SaveFileName))
                {
                    var playlist = (PlaylistDto)serializer.Deserialize(fileStream, typeof(PlaylistDto)) ?? new PlaylistDto();

                    var existingEpisodes   = playlist.Episodes ?? new EpisodeDto[0];
                    var concatenedEpisodes = existingEpisodes.Concat(new[] { dtoToSave }).ToArray();
                    majedPlaylist = new PlaylistDto {
                        Episodes = concatenedEpisodes
                    };
                }

                File.Delete(SaveFileName);
            }
            else
            {
                majedPlaylist = new PlaylistDto {
                    Episodes = new[] { dtoToSave }
                };
            }

            using (var fileStream = File.CreateText(SaveFileName))
            {
                serializer.Serialize(fileStream, majedPlaylist);
            }

            return(Task.CompletedTask);
        }
Example #7
0
        private async void btnAddPlaylist_Click(object sender, EventArgs e)
        {
            Playlist playlist = new Playlist();

            if (playlist.ShowDialog() == DialogResult.OK)
            {
                var playlistDto = new PlaylistDto
                {
                    HostId = _selectedHost.Id,
                    Name   = playlist.PlaylistName,
                    UserId = _userId
                };

                using (var client = new HttpClient())
                {
                    InitializeClient(client);
                    var response = await client.PostAsJsonAsync <PlaylistDto>("playlists", playlistDto).ConfigureAwait(false);

                    if (response.IsSuccessStatusCode)
                    {
                        playlistDto = await response.Content.ReadAsAsync <PlaylistDto>().ConfigureAwait(false);

                        _playlists.Add(playlistDto);
                        lstPlaylists.Items.Add(FormatPlaylist(playlistDto));
                    }
                    else
                    {
                        ShowErrorMessage(GetErrorMessageFromResponse(response));
                    }
                }
            }
        }
Example #8
0
        public void UpsertPlaylists_ShouldInsertNewItems()
        {
            var sequences = new List <ExportedPlaylistSimpleDto>();

            for (int i = 0; i < 3; ++i)
            {
                var s = new PlaylistDto(-1, "p" + i, "", -1, false, testLibrary.LibraryId, DateTime.Now, UniqueIdUtil.GenerateUniqueId());
                sequences.Add(new ExportedPlaylistSimpleDto(s, null));
            }

            var ids = new Dictionary <string, long>();

            repository.UpsertPlaylists(sequences, ids);

            var retSequences = repository.GetPlaylistsInLibrary(testLibrary.LibraryId, GetFirstPage(), "").Result.Results;
            var expectedIds  = new Dictionary <string, long>();

            foreach (var s in retSequences)
            {
                expectedIds[s.UniqueId] = s.SequenceId;
            }

            var expectedSequences = sequences.Select(p => p.Details).ToList();

            CollectionAssert.AreEquivalent(expectedSequences, retSequences);
            CollectionAssert.AreEquivalent(expectedIds, ids);
        }
Example #9
0
        public JsonResult CreateCopyByShareCode(string shareCodeShortId, string urlFriendlyEntityTitle, Guid folderId)
        {
            ShareCode shareCode = ShareCodeDao.GetByShortIdAndEntityTitle(shareCodeShortId, urlFriendlyEntityTitle);

            if (shareCode == null)
            {
                throw new ApplicationException("Unable to locate shareCode in database.");
            }

            if (shareCode.EntityType != ShareableEntityType.Playlist)
            {
                throw new ApplicationException("Expected shareCode to have entityType of Playlist");
            }

            //  Never return the sharecode's playlist reference. Make a copy of it to give out so people can't modify the original.
            Playlist playlistToCopy = PlaylistDao.Get(shareCode.EntityId);

            Folder folder = FolderDao.Get(folderId);

            var playlistCopy = new Playlist(playlistToCopy);

            folder.AddPlaylist(playlistCopy);

            PlaylistManager.Save(playlistCopy);

            PlaylistDto playlistDto = PlaylistDto.Create(playlistCopy);

            return(new JsonDataContractActionResult(playlistDto));
        }
Example #10
0
        public ActionResult ListTracks(string playlistName)
        {
            if (playlistName == null)
            {
                throw new ArgumentNullException("playlistName");
            }

            var         user     = (UserDto)Session["user"];
            PlaylistDto playlist = _playlistsDao.GetPlaylistForUser(user.Username, playlistName);

            return(View(new ListTracksModel
            {
                PlaylistName = playlist.PlaylistName,
                Username = playlist.Username,
                PlaylistLength = TimeSpan.FromSeconds(playlist.PlaylistLengthInSeconds),
                PlaylistTracks = playlist.PlaylistTrackList.Select(t => new PlaylistTrackModel
                {
                    SequenceNumber = t.SequenceNumber,
                    TrackName = t.TrackName,
                    Artist = t.Artist,
                    Genre = t.Genre,
                    Length = TimeSpan.FromSeconds(t.TrackLengthInSeconds)
                }).ToList()
            }));
        }
Example #11
0
        public PlaylistDto Create(PlaylistDto playlistDto)
        {
            PlaylistDto savedPlaylistDto;

            using (ITransaction transaction = Session.BeginTransaction())
            {
                User user = UserManager.Get(playlistDto.UserId);

                Playlist playlist = new Playlist(playlistDto.Id);
                playlistDto.SetPatchableProperties(playlist);

                user.AddPlaylist(playlist);

                List <PlaylistItem> playlistItems = new List <PlaylistItem>();
                foreach (PlaylistItemDto dto in playlistDto.Items)
                {
                    PlaylistItem playlistItem = new PlaylistItem(dto.Id, dto.Title, dto.Cid, dto.Song.Id, dto.Song.Type, dto.Song.Title, dto.Song.Duration, dto.Song.Author);
                    dto.SetPatchableProperties(playlistItem);
                    playlistItems.Add(playlistItem);
                }
                playlist.AddItems(playlistItems);

                PlaylistManager.Save(playlist);
                savedPlaylistDto = PlaylistDto.Create(playlist);

                transaction.Commit();
            }

            return(savedPlaylistDto);
        }
Example #12
0
        public async Task <PlaylistDto> CreateAsync(PlaylistDto item)
        {
            var result = _context.Playlists.Add(PlaylistConverter.Convert(item));
            await _context.SaveChangesAsync();

            return(PlaylistConverter.Convert(result.Entity));
        }
Example #13
0
        public ActionResult Get(Guid id)
        {
            Playlist    playlist    = PlaylistDao.Get(id);
            PlaylistDto playlistDto = PlaylistDto.Create(playlist);

            return(new JsonDataContractActionResult(playlistDto));
        }
Example #14
0
 public ActionResult Create(PlaylistDto playlistDTO)
 {
     try
     {
         if (playlistDTO.FileImage != null)
         {
             playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
             playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
             playlistDTO.FileImage = null;
         }
         else
         {
             playlistDTO.PlaylistImage = "default.png";
         }
         var data = ApiService.CreatePlaylist(playlistDTO);
         if (data != null)
         {
             return(RedirectToAction("Index", "Playlist", new { id = Session["id"] }));
         }
         return(RedirectToAction("Index", new { id = playlistDTO.UserID }));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(RedirectToAction("Index", new { id = playlistDTO.UserID }));
     }
 }
Example #15
0
        public void DeletePlaylist_NextToBigPlaylist_NoStackOverflowException()
        {
            User user = Helpers.CreateUser();

            Guid firstPlaylistId = user.Playlists.First().Id;

            PlaylistDto playlistDto = Helpers.CreatePlaylistDto(user.Id);

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            var result = (JsonServiceStackResult)PlaylistController.Create(playlistDto);

            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();

            var createdPlaylistDto = (PlaylistDto)result.Data;

            const int numItemsToCreate = 150;
            List <PlaylistItemDto> playlistItemDtos = Helpers.CreatePlaylistItemsDto(numItemsToCreate,
                                                                                     createdPlaylistDto.Id);

            foreach (var splitPlaylistItemDtos in Split(playlistItemDtos, 50))
            {
                NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
                PlaylistItemController.CreateMultiple(splitPlaylistItemDtos);
                NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();
            }

            NHibernateSessionManager.Instance.OpenSessionAndBeginTransaction();
            //  Now delete the first playlist.
            PlaylistController.Delete(firstPlaylistId);
            NHibernateSessionManager.Instance.CommitTransactionAndCloseSession();
        }
Example #16
0
        public async Task <PlaylistDto> CreateUserPlaylistWithTitle(string title)
        {
            var         playlistModel = tidlSession.CreateUserPlaylist(title);
            PlaylistDto res           = await PlaylistDto.ConvertToDTO(playlistModel);

            return(res);
        }
Example #17
0
 public IHttpActionResult CreatePlaylist(PlaylistDto playlist)
 {
     if (new Repositories().CreatePlaylist(playlist))
     {
         return(Ok());
     }
     return(InternalServerError());
 }
Example #18
0
        public ActionResult DeleteTrackFromPlaylist(DeleteTrackFromPlaylistModel model)
        {
            var         user     = (UserDto)Session["user"];
            PlaylistDto playlist = _playlistsDao.GetPlaylistForUser(user.Username, model.PlaylistName);

            _playlistsDao.DeleteTrackFromPlaylist(playlist, model.SequenceNumber);
            return(RedirectToAction("ListTracks", "PlaylistTracks", new { playlistName = model.PlaylistName }));
        }
Example #19
0
 public bool CreatePlaylist(PlaylistDto playlist)
 {
     if (new PlaylistBus().CreatePlaylist(playlist))
     {
         return(true);
     }
     return(false);
 }
Example #20
0
 public static Playlist Convert(PlaylistDto playlist)
 {
     return(new Playlist
     {
         Id = playlist.Id,
         Title = playlist.Title
     });
 }
Example #21
0
 public CreatePlaylistWindow(string windowTitle, ISongLoader songLoader, PlaylistDto playlist)
 {
     SongLoader = songLoader;
     InitializeComponent();
     Title               = windowTitle;
     PlaylistName        = playlist?.Name;
     TbPlaylistName.Text = playlist?.Name ?? string.Empty;
     CheckedSongs        = playlist?.Songs.ToList() ?? new();
 }
Example #22
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);
        }
Example #23
0
        public ActionResult Save([FromBody] JObject json)
        {
            var p        = JObject.Parse(json.ToString());
            var playlist = PlaylistDto.FromJson(p);

            //Console.WriteLine(song);
            _ps.Save(playlist);
            return(Ok());
        }
Example #24
0
        public async Task <ActionResult> ManagePlaylistSongs(int playlist_id)
        {
            AbstractPlaylistDto retObj = new PlaylistDto();

            ViewBag.PlaylistId = playlist_id;
            retObj             = await _playlistEntity.GetById(playlist_id);

            return(View(retObj));
        }
Example #25
0
        public ActionResult Update(PlaylistDto playlistDto)
        {
            Playlist playlist = Playlist.Create(playlistDto);

            PlaylistManager.Update(playlist);

            PlaylistDto updatedPlaylistDto = PlaylistDto.Create(playlist);

            return(new JsonServiceStackResult(updatedPlaylistDto));
        }
Example #26
0
        public ActionResult Update(PlaylistDto playlistDto)
        {
            Playlist playlist = Playlist.Create(playlistDto);

            PlaylistManager.Update(playlist);

            PlaylistDto updatedPlaylistDto = PlaylistDto.Create(playlist);

            return(new JsonDataContractActionResult(updatedPlaylistDto));
        }
Example #27
0
        /// <summary>
        ///     Generate a PlaylistDto which has the User as its parent.
        /// </summary>
        /// <returns></returns>
        public PlaylistDto CreatePlaylistDto(Guid userIdOverride, string title)
        {
            var playlistDto = new PlaylistDto
            {
                UserId = userIdOverride,
                Title  = title
            };

            return(playlistDto);
        }
Example #28
0
 public ActionResult UpdatePlAdmin(PlaylistDto playlistDTO)
 {
     try
     {
         var UserId = (UserDTO)Session[CommonConstants.USER_SESSION];
         playlistDTO.UserID = UserId.ID;
         //playlistDTO.UserID = 31;
         //get Image have exist
         var currentFileName = ApiService.GetPlaylistById(playlistDTO.ID).PlaylistImage;
         //check name have deafault if exist ==> dont delete
         if (currentFileName == "default.png")
         {
             if (playlistDTO.FileImage != null)
             {
                 playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
                 playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
                 playlistDTO.FileImage = null;
             }
             else
             {
                 playlistDTO.PlaylistImage = "default.png";
             }
         }
         else
         {
             if (playlistDTO.FileImage != null)
             {
                 //delete file
                 var filePath = Server.MapPath(path + currentFileName);
                 if (System.IO.File.Exists(filePath))
                 {
                     System.IO.File.Delete(filePath);
                 }
                 playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
                 playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
                 playlistDTO.FileImage = null;
             }
             else
             {
                 playlistDTO.PlaylistImage = currentFileName;
             }
         }
         var data = ApiService.UpdatePlaylist(playlistDTO);
         if (data != null)
         {
             return(RedirectToAction("ViewAddPlaylist"));
         }
         return(RedirectToAction("EditPlAdmin", new { id = playlistDTO.ID }));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(RedirectToAction("EditPlAdmin", new { id = playlistDTO.ID }));
     }
 }
 public ActionResult UpdatePlaylist(PlaylistDto playlistDTO)
 {
     try
     {
         //get Image have exist
         var currentFileName = ApiService.GetPlaylistById(playlistDTO.ID).PlaylistImage;
         //check name have deafault if exist ==> dont delete
         if (currentFileName == "default.png")
         {
             if (playlistDTO.FileImage != null)
             {
                 playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
                 playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
                 playlistDTO.FileImage = null;
             }
             else
             {
                 playlistDTO.PlaylistImage = "default.png";
             }
         }
         else
         {
             if (playlistDTO.FileImage != null)
             {
                 //delete file
                 var filePath = Server.MapPath(path + currentFileName);
                 if (System.IO.File.Exists(filePath))
                 {
                     System.IO.File.Delete(filePath);
                 }
                 playlistDTO.PlaylistImage = DateTime.Now.Ticks + playlistDTO.PlaylistImage + ".png";
                 playlistDTO.FileImage.SaveAs(Server.MapPath(path + playlistDTO.PlaylistImage));
                 playlistDTO.FileImage = null;
             }
             else
             {
                 playlistDTO.PlaylistImage = currentFileName;
             }
         }
         var data = ApiService.UpdatePlaylist(playlistDTO);
         if (data != null)
         {
             SetAlert("Update success!", "success");
             return(RedirectToAction("PersonalUser", "PersonalUser", new { id = Session["UserId"] }));
         }
         SetAlert("Update fail!", "danger");
         return(RedirectToAction("EditPLaylist", new { id = playlistDTO.ID }));
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         SetAlert("Update fail!", "danger");
         return(RedirectToAction("EditPLaylist", new { id = playlistDTO.ID }));
     }
 }
Example #30
0
        public void Patch(Guid id, PlaylistDto playlistDto)
        {
            using (ITransaction transaction = Session.BeginTransaction())
            {
                Playlist playlist = PlaylistManager.Get(id);
                playlistDto.SetPatchableProperties(playlist);
                PlaylistManager.Update(playlist);

                transaction.Commit();
            }
        }