Example #1
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
            }
        }
Example #2
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)
                }
                    );
            }
        }
Example #3
0
        /// <summary>
        /// Handles the SelectionChanged event of the Combobox_Options control.
        /// Logic for all of the the different selection options
        /// Sorry to the person reading this. I should definitely have called methods instead of writing so much code.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SelectionChangedEventArgs"/> instance containing the event data.</param>
        private async void Combobox_Options_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Amount of selected items
            int selectedAmount = gridViewMovies.SelectedItems.Count;

            // Get the ComboBox instance
            ComboBox comboBox = sender as ComboBox;

            string selectedName;

            try
            {
                selectedName = comboBox.SelectedValue.ToString();
            }
            catch (System.NullReferenceException nullReffEx)
            {
                //Catches if there is selectedValue is null
                //This occurs if the combobox is reset. Since the selection is changed into an invalid value the method must be stopped
                selectedName = nullReffEx.ToString();

                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;

                //Exiting method.
                return;
            }

            //If no movies are selected return
            if (selectedAmount == 0)
            {
                await new MessageDialog(
                    "No items are selected",
                    //Failed to (Open/Edit/Delete/Add to ToWatch list/Add to Watched list)
                    "Failed to " + selectedName).ShowAsync(); //Display message

                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;
                return;
            }

            //Creates string with all selected MovieNames
            var movies = gridViewMovies.SelectedItems;

            string selectedMoviesString = "";

            foreach (var m in movies)
            {
                var movie = m as Movie;

                selectedMoviesString += movie.Title + "\r\n";
            }


            // Logic for reading the selected combobox items is written in the if tests below



            //SELECTED "Open" IN THE COMBOBOX
            if (selectedName == "Open")
            {
                //If multiple movies are selected
                if (selectedAmount > 1)
                {
                    await new MessageDialog("Open movies failed", "You can only open 1 movie at the same time").ShowAsync(); //Display message

                    //Resets the combobox
                    comboBox_Options.SelectedIndex = -1;
                    //Exit method
                    return;
                }


                //Opens movie
                Movie selectedMovie = gridViewMovies.SelectedItem as Movie;

                await Task.Delay(50);

                //Creating parameter for tapped movie object
                var parameters = selectedMovie;


                //Navigate to new page, while also sending the Movie object parameters. T
                //he parameters are handled in the override OnNavigatedTo method in MoviePage
                Frame.Navigate(typeof(MoviePage), parameters);


                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;
                return;
            }



            //SELECTED "Edit" IN THE COMBOBOX
            if (selectedName == "Edit")
            {
                //If more than 1 movie is selected
                if (selectedAmount > 1)
                {
                    await new MessageDialog("You can only edit 1 movie at the same time", "Edit movies failed").ShowAsync(); //Display message

                    //Resets the combobox
                    comboBox_Options.SelectedIndex = -1;
                    //Exit method
                    return;
                }

                //Saving The chosen Movie object
                Movie selectedMovie = gridViewMovies.SelectedItem as Movie;

                await Task.Delay(50);

                //Creating parameter for tapped movie object
                var parameters = selectedMovie;


                //Task delay to ensure that the parameters are loaded correctly



                //Navigate to new page, while also sending the Movie object parameters. T
                //he parameters are handled in the override OnNavigatedTo method in EditMoviePage
                Frame.Navigate(typeof(EditMoviePage), parameters);


                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;
                return;
            }



            //SELECTED "Delete" IN THE COMBOBOX
            if (selectedName == "Delete")
            {
                var userMessage = new MessageDialog(
                    //Fill body with names of all the selected movie
                    selectedMoviesString,

                    //Title
                    "Are you sure you want to delete the selected movies shown below?\r\n");

                //Logic for deleteing all of the selected items

                //To prevent users accidentally deleting movies users must accept this option in a popup

                //Using delegate command for yes and no buttons
                userMessage.Commands.Add(new UICommand("Yes!", async delegate(IUICommand command)
                {
                    //Looping through all elements that are selected
                    ObservableCollection <Movie> toRemove = new ObservableCollection <Movie>();

                    //Creates a list of all the objects that are to be removed
                    //This is because it's not possible to modify the same list that is enumerating. (without deleting an incorrect amount of objects)
                    foreach (Movie elem in movies)
                    {
                        toRemove.Add(elem);
                    }

                    // Removing Movie objects that are stored in the toRemoveList
                    foreach (Movie remove in toRemove)

                    {
                        //Removing objects from TableItems ObservableCollection. (Bound to gridViewModels)
                        TableItems.Remove(remove);
                        await DeleteMovieAsync(remove.MovieId);
                    }
                }));

                userMessage.Commands.Add(new UICommand("No!", delegate(IUICommand command)
                {
                    //Resets the combobox
                    comboBox_Options.SelectedIndex = -1;

                    //exits method
                    return;
                }));

                //Open the popup specified above
                await userMessage.ShowAsync();

                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;
            }



            //SELECTED "Add to Towatch" or "Add to watched" IN THE COMBOBOX
            if (selectedName == "Add to ToWatch list" || selectedName == "Add to Watched list")
            {
                //Getting all user owned lists with a httpRequest
                ObservableCollection <AllList> userLists = await ListCalls.GetTokenOwnerLists(LoginPage.token);

                //Id of the chosen userlist
                Nullable <int> chosenUserList = null;

                //Checking the id for the lists owned by the user
                foreach (AllList ali in userLists)
                {
                    if (selectedName == "Add to ToWatch list")
                    {
                        //Checking for the for ToWatch list
                        if (ali.ListName == "ToWatch")
                        {
                            chosenUserList = ali.ListId;
                            await new MessageDialog("", chosenUserList.ToString()).ShowAsync();
                        }
                    }

                    if (selectedName == "Add to Watched list")
                    {
                        //Checking for the id for Watched list
                        if (ali.ListName == "Watched")
                        {
                            chosenUserList = ali.ListId;
                            await new MessageDialog("", chosenUserList.ToString()).ShowAsync();
                        }
                    }
                }

                //Checking if userlist was defined
                if (chosenUserList == null)
                {
                    //Resets the combobox
                    comboBox_Options.SelectedIndex = -1;
                    //returning if not defined
                    return;
                }

                //Posting all of the selected movies to the chosen list specified above (chosenUserList)
                foreach (Movie elem in movies)
                {
                    ListItem newListItem = new ListItem()
                    {
                        MovieId = elem.MovieId,

                        //converting nullable int to int.
                        //The convertion will succeed since I have already checked that the int is not null
                        ListId = Convert.ToInt32(chosenUserList)
                    };
                    //api/ListItems
                    string feedback = await ListItemCalls.PostListItem(newListItem);

                    //
                    //await new MessageDialog(feedback, "Added to list?").ShowAsync();
                }

                //Resets the combobox
                comboBox_Options.SelectedIndex = -1;
            }
        }