Пример #1
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)
                }
                    );
            }
        }
Пример #2
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
            }
        }