Ejemplo n.º 1
0
        public Result RemovePlaylist([FromBody] RemovePlaylistRequest request)
        {
            try
            {
                if (request.Playlist.Id == (Domain.Objects.Playlist.ALL_ID + "") || request.Playlist.Id == (Domain.Objects.Playlist.LIKED_ID + ""))
                {
                    return new Result()
                           {
                               Success = false, Message = "Can't delete the [All] or [Liked] playlist"
                           }
                }
                ;

                using (DAL.DALManager mgr = new DAL.DALManager(settings.Value.DatabasePath))
                {
                    var playlist = mgr.Get <Domain.Objects.Playlist>(int.Parse(request.Playlist.Id));

                    if (playlist == null)
                    {
                        return new Result()
                               {
                                   Success = false, Message = "Playlist not found"
                               }
                    }
                    ;

                    mgr.Delete <Domain.Objects.Playlist>(playlist);
                    mgr.DeleteAllTracksFromPlaylist(playlist.Id);

                    return(new Result()
                    {
                        Success = true
                    });
                }
            }
            catch (Exception ex)
            {
                return(GetErrorResultFromException <Result>(ex));
            }
        }