Example #1
0
        //Takes the input from the user and runs a search based on them. Takes the results and places them in a collection that can be data binded later. Takes the user to the results page.
        private async void Search_Click(object sender, RoutedEventArgs e)
        {
            sharedData.isAdvancedSearch = false;
            sharedData.SearchBoxTerm    = SearchBox.Text;

            String SearchTerm = SearchBox.Text;
            MusicSearchRootObject musicSearchRootObject = new MusicSearchRootObject();
            Retriever             retriever             = new Retriever();

            //Errors if things are missing
            if (SearchOptions.Content.Equals("Select"))
            {
                WarningBlock.Text = "Please select a search option";
                return;
            }
            if (SearchTerm.Equals(""))
            {
                WarningBlock.Text = "Please enter a search term";
                return;
            }

            WarningBlock.Text = "";

            //Calls API for root objects
            if (SearchOptions.Content.Equals("Artist"))
            {
                sharedData.isArtistSearch = true;
                musicSearchRootObject     = await retriever.GetTrackSearchResults(SearchTerm, "", false, false);
            }
            else
            {
                sharedData.isArtistSearch = false;
                musicSearchRootObject     = await retriever.GetTrackSearchResults(SearchTerm, "", false, true);
            }

            sharedData.Music.Clear();
            sharedData.SearchTerm = SearchTerm;

            SearchResults = musicSearchRootObject.message.body.track_list;
            //Making the observable collection of the results for the results page from the root object
            foreach (TrackList trackList in SearchResults)
            {
                MusicViewModel music = new MusicViewModel()
                {
                    TrackName     = trackList.track.track_name,
                    TrackId       = "" + trackList.track.track_id,
                    CommonTrackId = "" + trackList.track.commontrack_id,
                    ArtistName    = trackList.track.artist_name
                };
                sharedData.Music.Add(music);
            }

            this.Frame.Navigate(typeof(ResultsPage), sharedData);
        }
Example #2
0
        //Same as previous method, just for advanced search.
        private async void AdvancedSearch_Click(object sender, RoutedEventArgs e)
        {
            sharedData.isAdvancedSearch        = true;
            sharedData.AdvancedSearchBoxTrack  = AdvancedSearchTrack.Text;
            sharedData.AdvancedSearchBoxArtist = AdvancedSearchArtist.Text;

            MusicSearchRootObject musicSearchRootObject = new MusicSearchRootObject();
            Retriever             retriever             = new Retriever();

            if (AdvancedSearchTrack.Text.Equals("") || AdvancedSearchArtist.Text.Equals(""))
            {
                sharedData.noArtistOrTrack = true;
                if (AdvancedSearchTrack.Text.Equals("") && AdvancedSearchArtist.Text.Equals(""))
                {
                    AdvancedWarningBlock.Text = "Please enter a search term";
                    return;
                }
            }
            else
            {
                sharedData.noArtistOrTrack = false;
            }

            AdvancedWarningBlock.Text = "";

            musicSearchRootObject = await retriever.GetTrackSearchResults(AdvancedSearchTrack.Text, AdvancedSearchArtist.Text, true, true);

            sharedData.Music.Clear();

            if (sharedData.noArtistOrTrack)
            {
                sharedData.SearchTerm = AdvancedSearchTrack.Text + AdvancedSearchArtist.Text;
            }
            else
            {
                sharedData.SearchTerm = AdvancedSearchTrack.Text + " by " + AdvancedSearchArtist.Text;
            }

            SearchResults = musicSearchRootObject.message.body.track_list;

            foreach (TrackList trackList in SearchResults)
            {
                MusicViewModel music = new MusicViewModel()
                {
                    TrackName     = trackList.track.track_name,
                    TrackId       = "" + trackList.track.track_id,
                    CommonTrackId = "" + trackList.track.commontrack_id,
                    ArtistName    = trackList.track.artist_name
                };
                sharedData.Music.Add(music);
            }

            this.Frame.Navigate(typeof(ResultsPage), sharedData);
        }