Esempio n. 1
0
 private void CreatePlaylistExecute()
 {
     var playlist = new Playlist
     {
         name = "MyPlaylist",
         user = Singleton.Singleton.Instance().CurrentUser,
         musics = new List<Music> {MusicForPlaylist}
     };
     if (MusicForPlaylist != null)
     {
         var post = new HttpRequestPost();
         try
         {
             ValidateKey.GetValideKey();
             var test = post.SavePlaylist(playlist, Singleton.Singleton.Instance().SecureKey,
                 Singleton.Singleton.Instance().CurrentUser);
             test.ContinueWith(delegate(Task<string> tmp)
             {
                 var res = tmp.Result;
                 if (res != null)
                 {
                     CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                         () =>
                         {
                             var stringJson = JObject.Parse(res).SelectToken("content").ToString();
                             var playList =
                                 (Playlist)
                                     JsonConvert.DeserializeObject(stringJson, new Playlist().GetType());
                             try
                             {
                                 ValidateKey.GetValideKey();
                                 var up = post.UpdatePlaylist(playList, MusicForPlaylist,
                                     Singleton.Singleton.Instance().SecureKey,
                                     Singleton.Singleton.Instance().CurrentUser);
                                 up.ContinueWith(delegate(Task<string> tmp2)
                                 {
                                     var res2 = tmp2.Result;
                                     if (res2 != null)
                                     {
                                         CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                                             CoreDispatcherPriority.Normal, RefreshPlaylist);
                                     }
                                 });
                             }
                             catch (Exception)
                             {
                                 new MessageDialog(loader.GetString("ErrorUpdatePlaylist")).ShowAsync();
                             }
                         });
                 }
             });
         }
         catch (Exception)
         {
             new MessageDialog(loader.GetString("ErrorUpdatePlaylist")).ShowAsync();
         }
     }
     else
     {
         new MessageDialog(loader.GetString("ErrorNoMusic")).ShowAsync();
     }
 }
Esempio n. 2
0
        public async Task<String> SavePlaylist(Playlist thePlaylist, string sha256, User myUser)
        {
            var request = (HttpWebRequest) WebRequest.Create(ApiUrl + "playlists/save");

            var postData = "playlist[user_id]=" + myUser.id + "&playlist[name]=" + thePlaylist.name + "&secureKey=" +
                           sha256 + "&user_id=" + myUser.id;
            return await GetHttpPostResponse(request, postData);
        }
Esempio n. 3
0
        public async Task<String> UpdateNamePlaylist(Playlist thePlaylist, string sha256, User myUser)
        {
            var test = new int[thePlaylist.musics.Count];
            var en = "[";
            for (var i = 0; i < thePlaylist.musics.Count; i++)
            {
                test[i] = thePlaylist.musics[i].id;
                if (i == thePlaylist.musics.Count - 1)
                    en += thePlaylist.musics[i].id;
                else
                    en += thePlaylist.musics[i].id + ",";
            }
            en += "]";
            var request = (HttpWebRequest) WebRequest.Create(ApiUrl + "playlists/update");

            var postData = "id=" + thePlaylist.id + "&playlist[name]=" + thePlaylist.name + "&playlist[music]=" + en +
                           "&secureKey=" + sha256 + "&user_id=" +
                           myUser.id;
            return await GetHttpPostResponse(request, postData);
        }
Esempio n. 4
0
        public async Task<String> UpdatePlaylist(Playlist thePlaylist, Music theMusic, string sha256, User myUser)
        {
            var request = (HttpWebRequest) WebRequest.Create(ApiUrl + "musics/addtoplaylist");

            var postData = "id=" + theMusic.id + "&playlist_id=" + thePlaylist.id + "&secureKey=" + sha256 + "&user_id=" +
                           myUser.id;
            return await GetHttpPostResponse(request, postData);
        }
Esempio n. 5
0
 public async Task<string> DeleteMusicFromPlaylist(Playlist myPlaylist, Music theMusic, string sha256,
     User myUser)
 {
     var request =
         (HttpWebRequest)
             WebRequest.Create(ApiUrl + "musics/delfromplaylist?id=" + theMusic.id + "&playlist_id=" +
                               myPlaylist.id + "&secureKey=" + sha256 + "&user_id=" + myUser.id);
     return await DoRequest(request);
 }
Esempio n. 6
0
 public async Task<string> DeletePlaylist(Playlist myPlaylist, string sha256, User myUser)
 {
     var request =
         (HttpWebRequest)
             WebRequest.Create(ApiUrl + "playlists/destroy?id=" + myPlaylist.id + "&secureKey=" + sha256 +
                               "&user_id=" + myUser.id);
     return await DoRequest(request);
 }