Beispiel #1
0
        /// <summary>
        /// Load an ObservableCollection with Games
        /// </summary>
        /// <param name="error_message"></param>
        /// <returns></returns>
        public void GetAllGames(out string error_message)
        {
            _originalGameList = null;
            GameCollection.Clear();
            error_message = "";

            try
            {
                using (_gameRepository)
                {
                    _originalGameList = _gameRepository.GetAllGames(out error_message);
                }
            }
            catch (Exception ex)
            {
                error_message = ex.ToString();
            }

            foreach (Game game in _originalGameList)
            {
                GameCollection.Add(game);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Filters the game collection
        /// </summary>
        /// <param name="formatIdString"></param>
        /// <param name="publisherIdString"></param>
        /// <param name="ratingString"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="gameName"></param>
        public void FilterGameCollection(string formatIdString, string publisherIdString, string ratingString, string beginDate, string endDate, string gameName)
        {
            // process the inputs
            int.TryParse(formatIdString, out int formatId);
            int.TryParse(publisherIdString, out int publisherId);
            int.TryParse(ratingString, out int rating);

            if (DateTime.TryParse(beginDate, out DateTime beginDT))
            {
                beginDate = beginDT.Date.ToShortDateString();
            }

            if (DateTime.TryParse(endDate, out DateTime endDT))
            {
                endDate = endDT.Date.ToShortDateString();
            }

            //GameCollection = (ObservableCollection<Game>)
            IEnumerable <Game> outputGameList =
                (from g in _originalGameList
                 where g.FormatId == (formatId == 0 ? g.FormatId : formatId) &&
                 g.PublisherId == (publisherId == 0 ? g.PublisherId : publisherId) &&
                 g.Rating == (rating == 0 ? g.Rating : rating) &&
                 g.GameName.ToLower().Contains(gameName.ToLower()) &&
                 (beginDate == null || beginDate == "" ? 1 == 1 : DateTime.Parse(g.ReleaseDate) >= DateTime.Parse(beginDate == "" ? g.ReleaseDate : beginDate)) &&
                 DateTime.Parse(g.ReleaseDate) <= DateTime.Parse(endDate == "" ? g.ReleaseDate : endDate)
                 orderby g.GameName, g.PublisherName, g.FormatName
                 select g);

            GameCollection.Clear();

            foreach (Game game in outputGameList)
            {
                GameCollection.Add(game);
            }
        }