/// <summary>Invoked when the Page is loaded and becomes the current source of a parent Frame. /// Saves the parametes as a Movie that can be retrieved in this class. /// </summary> /// <param name="e"> /// Event data that can be examined by overriding code. The event data is representative of the pending navigation that will load the current Page. Usually the most relevant property to examine is Parameter. /// </param> protected override void OnNavigatedTo(NavigationEventArgs e) { try { var parameters = (e.Parameter as MovieHunter.DataAccess.Models.Movie); if (parameters != null) { MovieContainer = parameters; } } catch { return; } }
/// <summary> /// Invoked when the Page is loaded and becomes the current source of a parent Frame. /// When a frame navigations to this page with parameters. /// The parameter is in this Case a Movie Object. This object is then saved in the MovieContainer object. /// This makes it easy to handle the object data. /// </summary> /// <param name="e"> /// Event data that can be examined by overriding code. The event data is representative of the pending navigation that will load the current Page. /// </param> protected override void OnNavigatedTo(NavigationEventArgs e) { try { var parameters = (e.Parameter as Movie); if (parameters != null) { //Adding to Movie MovieContainer object MovieContainer = parameters; } } catch { //Could not add parameter to Movie Object return; } }
/// <summary> /// Handles the AddMovie event of the Btn control. /// Checking User input for criterias. /// If criterias are not followed it will write an error code to the user /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Windows.UI.Xaml.RoutedEventArgs"/> instance containing the event data.</param> private async void Btn_AddMovie(object sender, Windows.UI.Xaml.RoutedEventArgs e) { //Resetting the output output_Movie.Text = ""; //Checks if every step in the addmovie method runs correctly bool addedSuccessfully = true; //Checks if the suggestionboxes does not contain values if (starId == 0 || directorId == 0 || writerId == 0 || genreId == 0) { //Makes the outPut textblock visible in the UI output_Movie.Visibility = Visibility.Visible; //Giving the user an error response output_Movie.Text += "Set values in all suggestion boxes\r\n"; //The method was not successful addedSuccessfully = false; } //Getting information from user input string movieTitle = inp_MovieTitle.Text; string movieImageLink = inp_MovieImageLink.Text; string movieSummary = inp_MovieSummary.Text; try { //Dont accept movie ratings of 0. All movies deserve to be number 1.. if (inp_MovieRating.Value == 0) { output_Movie.Text += "Set a Movie Rating\r\n"; addedSuccessfully = false; } double movieRating = inp_MovieRating.Value; } //If the value is not a number. This happened when using a textblock. Its using a slider now.. catch { output_Movie.Visibility = Visibility.Visible; output_Movie.Text += "Movie Rating must be an integer between 0 and 10\r\n"; } //If the above code was not run successfully dont upload data if (!addedSuccessfully) { return; } //Movielinks must be more that 10 characters. I should add try catch to verify if the link is valid if (movieImageLink.Length < 10) { movieImageLink = "https://pdfimages.wondershare.com/forms-templates/medium/movie-poster-template-3.png"; } //Create object for post request try { //Creating Movie object DataAccess.Models.Movie newMovie = new DataAccess.Models.Movie() { Star = starId, WriterId = writerId, DirectorId = directorId, GenreId = genreId, Title = movieTitle, CoverImage = movieImageLink, Summary = movieSummary, Rating = Convert.ToByte(inp_MovieRating.Value) }; //Posting movie object output_Movie.Text = await MovieCalls.PostMovieAsync(newMovie); } //If object creation fails catch { //output UI output_Movie.Text += "Could not create movie object\r\n"; } }