protected override void InitializeCommands()
        {
            Submit = new RelayCommand(o => {
                ApplicationViewModel.RestClient.ExecuteAsync <Artist>(ApplicationViewModel.RequestFactory.AddArtistRequest(model),
                                                                      (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        ApplicationViewModel.DisplayView.Execute(r.Data);
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*Response<Artist> response = DataProvider.SaveArtist(model);
                 * if (!response.Status)
                 * {
                 *  ApplicationViewModel.HandleError(response.Error);
                 * }
                 * else ApplicationViewModel.DisplayView.Execute(response.Content);*/
            });
            base.InitializeCommands();
        }
Esempio n. 2
0
 protected override void InitializeCommands()
 {
     base.InitializeCommands();
     RegisterCommand = new RelayCommand(a =>
     {
         string pass       = a as string;
         RegisterForm form = new RegisterForm
         {
             Login    = login,
             Password = pass,
             Email    = email
         };
         RestClient.ExecuteAsync <User>(RequestFactory.RegisterRequest(form), (resp, handle) =>
         {
             if (resp.Succeeded())
             {
                 ApplicationViewModel.LoginPage.Execute(null);
             }
             else
             {
                 ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
             }
         });
     });
 }
        public DisplayArtistViewModel(ApplicationViewModel applicationViewModel, IResponseDataProvider dataProvider, long artistId) : base(applicationViewModel, dataProvider)
        {
            RestClient.ExecuteAsync <ArtistWithAlbums>(RequestFactory.GetArtistWithAlbumsRequest(artistId),
                                                       (r, c) =>
            {
                if (r.Succeeded())
                {
                    Albums = new ObservableCollection <Album>(r.Data.Albums);
                    Model  = r.Data.Artist;

                    Console.WriteLine(Model.Name);
                }
                else
                {
                    ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                }
            });


            RefreshComments(artistId, 1);

            ApplicationViewModel.RestClient.ExecuteAsync <Rating>(
                RequestFactory.GetRatingRequest(EntityType.ARTIST, artistId, LoginSession.Authentication.User.Id),
                (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    rating     = resp.Data;
                    UserRating = resp.Data == null ? 0 : resp.Data.Value;
                }
                else
                {
                    resp.ExceptionResponse();
                    ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                }
            });

            RestClient.ExecuteAsync <double>(RequestFactory.AverageRatingRequest(EntityType.ARTIST, artistId),
                                             (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    averageRating = resp.Data;
                }
                else
                {
                    ;
                }
            });

            /*Response<Artist> respArtist = DataProvider.GetArtistById(artistId);
             * Response<IList<Album>> respAlbums = DataProvider.GetAlbumsByArtist(artistId);
             * if (!respArtist.Status || !respAlbums.Status)
             * {
             *  ApplicationViewModel.HandleError(!respArtist.Status ? respArtist.Error : respAlbums.Error);
             *  return;
             * }
             * Albums = new ObservableCollection<Album>(respAlbums.Content);
             * Model = respArtist.Content;*/
        }
        public DisplayAlbumViewModel(ApplicationViewModel applicationViewModel, IResponseDataProvider dataProvider, long albumId) : base(applicationViewModel, dataProvider)
        {
            RestClient.ExecuteAsync <AlbumWithSongs>(RequestFactory.GetAlbumWithSongsRequest(albumId),
                                                     (r, c) =>
            {
                if (r.Succeeded())
                {
                    Songs = new ObservableCollection <Song>(r.Data.Songs);
                    Model = r.Data.Album;
                }
                else
                {
                    ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                }
            });

            RefreshComments(albumId, 1);

            ApplicationViewModel.RestClient.ExecuteAsync <Rating>(
                RequestFactory.GetRatingRequest(EntityType.ALBUM, albumId, LoginSession.Authentication.User.Id),
                (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    rating     = resp.Data;
                    UserRating = resp.Data == null ? 0 : resp.Data.Value;
                }
                else
                {
                    resp.ExceptionResponse();
                    ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                }
            });

            RestClient.ExecuteAsync <double>(RequestFactory.AverageRatingRequest(EntityType.ALBUM, albumId),
                                             (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    averageRating = resp.Data;
                }
                else
                {
                    ;
                }
            });

            /*Response<Album> respAlbum = DataProvider.GetAlbumById(albumId);
             * Response<IList<Song>> respSongs = DataProvider.GetSongsFromAlbum(albumId);
             * if (!respAlbum.Status || !respSongs.Status)
             * {
             *  ApplicationViewModel.HandleError(!respAlbum.Status ? respAlbum.Error : respSongs.Error);
             *  return;
             * }
             * Songs = new ObservableCollection<Song>(respSongs.Content);
             * Model = respAlbum.Content;*/
        }
        public DisplaySongViewModel(ApplicationViewModel applicationViewModel, IResponseDataProvider dataProvider, long songId) : base(applicationViewModel, dataProvider)
        {
            /*Response<Song> response = DataProvider.GetSongById(songId);
             * if (!response.Status)
             * {
             *  ApplicationViewModel.HandleError(response.Error);
             *  return;
             * }
             * Model = response.Content;*/
            ApplicationViewModel.RestClient.ExecuteAsync <Song>(
                ApplicationViewModel.RequestFactory.GetSongRequest(songId),
                (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    Model = resp.Data;
                }
                else
                {
                    ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                }
            });
            RefreshComments(songId, 1);

            ApplicationViewModel.RestClient.ExecuteAsync <Rating>(
                RequestFactory.GetRatingRequest(EntityType.SONG, songId, LoginSession.Authentication.User.Id),
                (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    rating     = resp.Data;
                    UserRating = resp.Data == null? 0 : resp.Data.Value;
                }
                else
                {
                    resp.ExceptionResponse();
                    ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                }
            });

            RestClient.ExecuteAsync <double>(RequestFactory.AverageRatingRequest(EntityType.SONG, songId),
                                             (resp, handle) =>
            {
                if (resp.Succeeded())
                {
                    averageRating = resp.Data;
                }
                else
                {
                    ;
                }
            });
        }
 protected override void InitializeCommands()
 {
     Logout = new RelayCommand(o =>
     {
         RestClient.ExecuteAsync(RequestFactory.LogoutRequest(), (resp, handle) =>
         {
             if (resp.Succeeded())
             {
                 ApplicationViewModel.LoginPage.Execute(null);
             }
             else
             {
                 ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
             }
         });
     });
     base.InitializeCommands();
 }
 private void RefreshComments(long modelId, int pageNumber)
 {
     RestClient.ExecuteAsync <Page <Comment> >(RequestFactory.FindCommentsRequest(EntityType.SONG, modelId, pageNumber),
                                               (resp, handle) =>
     {
         if (resp.Succeeded())
         {
             CommentPage = resp.Data;
             foreach (var c in CommentPage.Items)
             {
                 Console.WriteLine(c.Content);
             }
         }
         else
         {
             ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
         }
     });
 }
Esempio n. 8
0
 protected override void InitializeCommands()
 {
     base.InitializeCommands();
     LoginCommand = new RelayCommand(a =>
     {
         string pass = a as string;
         RestClient.ExecuteAsync <Authentication>(RequestFactory.LoginRequest(login, pass), (resp, handle) =>
         {
             Console.WriteLine(resp.Content);
             if (resp.Succeeded())
             {
                 LoginSession.Authentication = resp.Data;
                 ApplicationViewModel.Home.Execute(null);
             }
             else
             {
                 ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
             }
         });
     });
 }
 private void UpdateUserRating()
 {
     if (rating != null)
     {
         rating.Value = userRating;
     }
     if (userRating < 1 || userRating > 5)
     {
         return;
     }
     RestClient.ExecuteAsync <Rating>(
         rating == null?
         RequestFactory.AddRatingRequest(new Rating()
     {
         EntityType = EntityType.SONG,
         EntityId   = Model.Id,
         Value      = UserRating,
         User       = LoginSession.Authentication.User
     }) : RequestFactory.UpdateRatingRequest(rating),
         (resp, handle) =>
     {
         if (resp.Succeeded())
         {
             rating    = resp.Data;
             var resp2 = RestClient.Execute <double>(RequestFactory.AverageRatingRequest(EntityType.SONG, Model.Id));
             if (resp2.Succeeded())
             {
                 AverageRating = resp2.Data;
             }
             else
             {
                 ApplicationViewModel.HandlExceptionResponse(resp2.ExceptionResponse());
             }
         }
         else
         {
             ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
         }
     });
 }
        public EditArtistViewModel(ApplicationViewModel applicationViewModel, IResponseDataProvider dataProvider, long artistId) : base(applicationViewModel, dataProvider)
        {
            ApplicationViewModel.RestClient.ExecuteAsync <Artist>(ApplicationViewModel.RequestFactory.GetArtistRequest(artistId),
                                                                  (r, c) =>
            {
                if (r.Succeeded())
                {
                    Model = r.Data;
                }
                else
                {
                    ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                }
            });

            /*Response<Artist> respArtist = DataProvider.GetArtistById(artistId);
             * if (!respArtist.Status)
             * {
             *  ApplicationViewModel.HandleError(respArtist.Error);
             *  return;
             * }
             * Model = respArtist.Content;*/
        }
Esempio n. 11
0
        public EditSongViewModel(ApplicationViewModel applicationViewModel, IResponseDataProvider dataProvider, long songId) : base(applicationViewModel, dataProvider)
        {
            ApplicationViewModel.RestClient.ExecuteAsync <Song>(ApplicationViewModel.RequestFactory.GetSongRequest(songId),
                                                                (r, c) =>
            {
                if (r.Succeeded())
                {
                    Model = r.Data;
                }
                else
                {
                    ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                }
            });

            /*
             * Response<Song> response = DataProvider.GetSongById(songId);
             * if (!response.Status)
             * {
             *  ApplicationViewModel.HandleError(response.Error);
             *  return;
             * }
             * Model = response.Content;   */
        }
        protected override void InitializeCommands()
        {
            base.InitializeCommands();

            Delete = new RelayCommand(o =>
            {
                IsClosing = true;


                ApplicationViewModel.RestClient.ExecuteAsync <Artist>(ApplicationViewModel.RequestFactory.DeleteSongRequest(model.Id),
                                                                      (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        ApplicationViewModel.DisplayView.Execute(model.Album);
                        ApplicationViewModel.ClearHistory();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*Response<bool> response = DataProvider.DeleteSong(model.Id);
                 * if (!response.Status) ApplicationViewModel.HandleError(response.Error);
                 * else
                 * {
                 *  ApplicationViewModel.DisplayView.Execute(model.Album);
                 *  ApplicationViewModel.ClearHistory();
                 * }*/
            });
            Home = new RelayCommand(o =>
            {
                IsClosing = true;
                ApplicationViewModel.Home.Execute(null);
            });
            Back = new RelayCommand(o =>
            {
                IsClosing = true;
                ApplicationViewModel.PreviousPage.Execute(null);
            });
            Edit = new RelayCommand(o =>
            {
                IsClosing = true;
                ApplicationViewModel.EditView.Execute(Model);
            });

            NextCommentPage     = new RelayCommand(o => RefreshComments(Model.Id, CommentPage.PageNumber + 1));
            PreviousCommentPage = new RelayCommand(o => RefreshComments(Model.Id, CommentPage.PageNumber - 1));
            PostComment         = new RelayCommand(o =>
            {
                Comment comment = new Comment()
                {
                    EntityType = EntityType.SONG,
                    User       = LoginSession.Authentication.User,
                    EntityId   = Model.Id,
                    Content    = CommentContent
                };
                RestClient.ExecuteAsync <Comment>(RequestFactory.AddCommentRequest(comment), (resp, handle) =>
                {
                    if (resp.Succeeded())
                    {
                        RefreshComments(Model.Id, 1);
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                    }
                });
            });

            AdminDeleteComment = new RelayCommand(o =>
            {
                if (!(o is Comment))
                {
                    return;
                }
                Comment comment = o as Comment;
                RestClient.ExecuteAsync(RequestFactory.DeleteCommentRequest(comment.Id), (resp, handle) =>
                {
                    if (resp.Succeeded())
                    {
                        RefreshComments(Model.Id, CommentPage.PageNumber);
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                    }
                });
            });
        }
        protected override void InitializeCommands()
        {
            base.InitializeCommands();
            Delete = new RelayCommand(o =>
            {
                ApplicationViewModel.RestClient.ExecuteAsync <Artist>(ApplicationViewModel.RequestFactory.DeleteArtistRequest(model.Id),
                                                                      (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        ApplicationViewModel.Search.Execute(model.Name);
                        ApplicationViewModel.ClearHistory();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*
                 * Response<bool> response = DataProvider.DeleteArtist(model.Id);
                 * if (!response.Status) ApplicationViewModel.HandleError(response.Error);
                 * else
                 * {
                 *  ApplicationViewModel.Search.Execute(model.Name);
                 *  ApplicationViewModel.ClearHistory();
                 * }*/
            });
            CreateAlbum = new RelayCommand(o =>
            {
                ApplicationViewModel.CreateView.Execute(new CreateAlbumViewModel(ApplicationViewModel, DataProvider, model));
            });

            NextCommentPage     = new RelayCommand(o => RefreshComments(Model.Id, CommentPage.PageNumber + 1));
            PreviousCommentPage = new RelayCommand(o => RefreshComments(Model.Id, CommentPage.PageNumber - 1));
            PostComment         = new RelayCommand(o =>
            {
                Comment comment = new Comment()
                {
                    EntityType = EntityType.ARTIST,
                    User       = LoginSession.Authentication.User,
                    EntityId   = Model.Id,
                    Content    = CommentContent
                };
                RestClient.ExecuteAsync <Comment>(RequestFactory.AddCommentRequest(comment), (resp, handle) =>
                {
                    if (resp.Succeeded())
                    {
                        RefreshComments(Model.Id, 1);
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                    }
                });
            });

            AdminDeleteComment = new RelayCommand(o =>
            {
                if (!(o is Comment))
                {
                    return;
                }
                Comment comment = o as Comment;
                RestClient.ExecuteAsync(RequestFactory.DeleteCommentRequest(comment.Id), (resp, handle) =>
                {
                    if (resp.Succeeded())
                    {
                        RefreshComments(Model.Id, CommentPage.PageNumber);
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(resp.ExceptionResponse());
                    }
                });
            });
        }
Esempio n. 14
0
        private void SearchByText(string text)
        {
            songPage   = null;
            albumPage  = null;
            artistPage = null;

            int amount = searchFocus == SearchFocus.Any ? 3 : 10;

            if (SearchFocus == SearchFocus.Any)
            {
                RestClient.ExecuteAsync <CommonSearchResult>(RequestFactory.CommonSearchRequest(text, Page, amount), (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        var data   = r.Data;
                        songPage   = data.songResult;
                        albumPage  = data.albumResult;
                        artistPage = data.artistResult;
                        ShowSearchResults();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });
            }

            if (SearchFocus == SearchFocus.Songs)
            {
                RestClient.ExecuteAsync <Page <Song> >(RequestFactory.SearchSongsRequest(text, Page, amount), (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        songPage = r.Data;
                        ShowSearchResults();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*Response<Page<Song>> response = DataProvider.SearchSongsByTitle(text, Page, amount);
                 * if (!response.Status)
                 * {
                 *  ApplicationViewModel.HandleError(response.Error);
                 *  return;
                 * }
                 * songPage = response.Content;*/
            }
            if (SearchFocus == SearchFocus.Albums)
            {
                RestClient.ExecuteAsync <Page <Album> >(RequestFactory.SearchAlbumsRequest(text, Page, amount), (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        albumPage = r.Data;
                        ShowSearchResults();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*Response<Page<Album>> response = DataProvider.SearchAlbumsByName(text, Page, amount);
                 * if (!response.Status)
                 * {
                 *  ApplicationViewModel.HandleError(response.Error);
                 *  return;
                 * }
                 * albumPage = response.Content;*/
            }
            if (SearchFocus == SearchFocus.Artists)
            {
                RestClient.ExecuteAsync <Page <Artist> >(RequestFactory.SearchArtistsRequest(text, Page, amount), (r, c) =>
                {
                    if (r.Succeeded())
                    {
                        artistPage = r.Data;
                        ShowSearchResults();
                    }
                    else
                    {
                        ApplicationViewModel.HandlExceptionResponse(r.ExceptionResponse());
                    }
                });

                /*Response<Page<Artist>> response = DataProvider.SearchArtistsByName(text, Page, amount);
                 * if (!response.Status)
                 * {
                 *  ApplicationViewModel.HandleError(response.Error);
                 *  return;
                 * }
                 * artistPage = response.Content;*/
            }
        }