Esempio n. 1
0
        /// <summary>Handles the UpdateMovie event of the Btn control.
        /// Creates the updated movie object
        /// Updates the database by sending a putRequest
        /// </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_UpdateMovie(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            Movie updateMovieObject = new Movie()
            {
                MovieId    = MovieContainer.MovieId,
                Title      = inp_MovieTitle.Text,
                Summary    = inp_MovieSummary.Text,
                DirectorId = MovieContainer.DirectorId,
                WriterId   = MovieContainer.WriterId,
                Star       = MovieContainer.Star,
                Rating     = MovieContainer.Rating,
                GenreId    = MovieContainer.GenreId,
                CoverImage = MovieContainer.CoverImage
            };

            //Sending PutRequest
            await MovieCalls.PutMovie(updateMovieObject, MovieContainer.MovieId);
        }
Esempio n. 2
0
        /// <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";
            }
        }
Esempio n. 3
0
        /// <summary>Gets the lists asynchronous.
        /// Getting listItems for the chosen list
        /// </summary>
        private async void GetListsAsync()
        {
            //Adding object to the list
            //If database api request fails delete listview content.
            ListItems.Clear();


            //Loading Output
            ListItems.Add(new AllListItems()
            {
                ListMessage = "Loading listItems"
            });

            // If the listId is not set
            if (ListId == null)
            {
                //The listId doesnt exist, and the user cant retrieve from database
                ListItems.Add(new AllListItems()
                {
                    ListMessage = "The list was not found"
                });
                return;
            }

            //Get Request to the server asking for listitems in specific list
            ObservableCollection <AllListItems> returnedCollection = await ListItemCalls.GetListItems(Convert.ToInt32(ListId));

            //There are no list items
            if (returnedCollection.Count == 0)
            {
                //Add message
                ListItems.Clear();
                ListItems.Add(new AllListItems()
                {
                    ListMessage = "No listitems was retrieved."
                });
                return;
            }

            //Clear list
            ListItems.Clear();

            //Getting the movie list for finding Movie name
            ObservableCollection <Movie> allMovies = await MovieCalls.GetMovies();

            //Looking through the list of items and adding it to the UI List
            foreach (AllListItems a in returnedCollection)
            {
                ListItems.Add(
                    new AllListItems()
                {
                    ListId     = a.ListId,
                    ListItemId = a.ListItemId,
                    MovieId    = a.MovieId,

                    //Looking through the movie list for the title of the movie
                    MovieName = MovieCalls.GetMovieNameFromList(allMovies, a.MovieId)
                }
                    );
            }
        }
Esempio n. 4
0
        /// <summary>Creates collection for all of the genres in the current list</summary>
        public async void GetAllLists()
        {
            //Getting the user owned lists
            ObservableCollection <AllList> userLists = await ListCalls.GetTokenOwnerLists(LoginPage.token);

            //Creating objects that contains the listId's
            AllList toWatchList = new AllList();
            AllList watchedList = new AllList();

            //Adding the listId's to the appropiat list object
            foreach (AllList n in userLists)
            {
                //Adding to ToWatch List object
                if (n.ListName == "ToWatch")
                {
                    toWatchList.ListId   = n.ListId;
                    toWatchList.ListName = n.ListName;
                }
                //Adding to watched List object
                if (n.ListName == "Watched")
                {
                    watchedList.ListId   = n.ListId;
                    watchedList.ListName = n.ListName;
                }
            }

            //Getting all the listItems from the ToWatch List
            ObservableCollection <AllListItems> allTowatchListObjects = await ListItemCalls.GetListItems(toWatchList.ListId);

            //Getting all the listItems from the ToWatch List
            ObservableCollection <AllListItems> allWatchedListObjects = await ListItemCalls.GetListItems(watchedList.ListId);

            //Getting All of the Movies
            allMovies = await MovieCalls.GetMovies();

            //Creating lists for storing allMovie object for the toWatch and watched list
            ObservableCollection <Movie> allToWatchMovies = new ObservableCollection <Movie>();
            ObservableCollection <Movie> allWatchedMovies = new ObservableCollection <Movie>();

            //Comparing the All ListObjects movie id with tall movies (Intensive task that can be optimised)
            foreach (Movie m in allMovies)
            {
                //ToWatch
                foreach (AllListItems toWatchI in allTowatchListObjects)
                {
                    //If the movie exists in the towatchlist add the Movie object to the new list
                    //This is so that the Movie object that contains all of the information can be displayed in the UI
                    if (m.MovieId == toWatchI.MovieId)
                    {
                        //Adding the movie to the new list
                        allToWatchMovies.Add(m);
                    }
                }
                //Watched
                foreach (AllListItems watched in allWatchedListObjects)
                {
                    //See comments on the foreach loop above
                    if (m.MovieId == watched.MovieId)
                    {
                        allWatchedMovies.Add(m);
                    }
                }
            }

            //Creating reference to the stackPanel that should contain the list
            StackPanel stack_toWatch = Stack_listViews;
            StackPanel stack_Watched = Stack_Watched;

            //Creating the stack lists in the ToWatch Tab
            DynamicListViewCreator("All Genres", allToWatchMovies, stack_toWatch);

            //Creating the stack lists in the Watched Tab
            DynamicListViewCreator("All Genres", allWatchedMovies, Stack_Watched);



            //The new lists can now be used to create seperate lists for every genreId that exists in the Movie collection lists

            //Firstly we need all of the Genre objects that excist.
            //Then we can compare all existing genreId's with the ones that exist in the Watched and toWatch lists.
            ObservableCollection <Genre> allGenres = await GenreCalls.GetGenres();

            //Looping through the allGenres list
            foreach (Genre existingGenres in allGenres)
            {
                //Creates a temporary list to store the movie that contain the current genre
                ObservableCollection <Movie> genreListWatched = new ObservableCollection <Movie>();
                foreach (Movie allWatched in allWatchedMovies)
                {
                    //Finding out that if the allWatched contains the genre
                    if (existingGenres.GenreId == allWatched.GenreId)
                    {
                        //Adding movie with same genre to the list
                        genreListWatched.Add(allWatched);
                    }
                }
                //If any movies got added create a new List in the UI
                if (genreListWatched.Count > 0)
                {
                    DynamicListViewCreator(existingGenres.GenreName, genreListWatched, Stack_Watched);
                }

                //Creates a temporary list to store the movie that contain the current genre
                ObservableCollection <Movie> genreListToWatch = new ObservableCollection <Movie>();
                foreach (Movie allToWatch in allToWatchMovies)
                {
                    //Finding out that if the allToWatch contains the genre
                    if (existingGenres.GenreId == allToWatch.GenreId)
                    {
                        //Adding movie with same genre to the list
                        genreListToWatch.Add(allToWatch);
                    }
                }
                //If any movies got added create a new List in the UI
                if (genreListToWatch.Count > 0)
                {
                    DynamicListViewCreator(existingGenres.GenreName, genreListToWatch, stack_toWatch);
                }
                //End of Genre Loop
            }
        }