Exemple #1
0
        /// <summary>
        /// Filters all games based on search terms. (Updates FilteredGames property)
        /// </summary>
        /// <param name="searchTerms">The terms to be searched for.</param>
        public void FilterGames(string searchTerms)
        {
            List <Game> _tempList = new List <Game>();

            // Loops over every game in StoreGameCollection, to add the games that fit the search terms to the temporary list defined above.
            foreach (Game game in StoreGameCollection)
            {
                if (game.Name.ToLower().Contains(searchTerms.ToLower()) && game.ReleaseDate.Date <= DateTime.Now)
                {
                    _tempList.Add(game);
                }
            }

            // Orders the temp list in alphabetical order.
            _tempList = _tempList.OrderBy(item => item.Name).ToList();

            // Clears the FilteredGames list
            FilteredGames.Clear();

            // Adds all the games from the temp list to the FilteredList, if they don't exist in the FilteredList already.
            foreach (Game game in _tempList)
            {
                FilteredGames.Add(game);
            }
        }
        //Constructor
        public LibraryViewModel()
        {
            _navigationHandler = NavigationHandler.Instance;

            foreach (Game game in Games)
            {
                FilteredGames.Add(game);
            }
        }