예제 #1
0
        public ActionResult GetByFilter(VideoGamesFilterQueryOptions filter)
        {
            var validationAnswerResult = IsValid();

            if (validationAnswerResult == null)
            {
                var videoGamesList = _manager.GetGamesWithFilter(filter);
                if (videoGamesList.Count() > 0)
                {
                    return(Ok(videoGamesList));
                }

                return(NotFound());
            }

            return(validationAnswerResult);
        }
        /// <summary>
        ///Вернуть список видеоигрудовлетворяющих устовиям поиска хранящихся в соответствующийх полях объекта класса FilterOptions
        /// </summary>
        /// <param name="filter">экземпляр класса содержащий параметры фильрации</param>
        /// <returns> Возвращает список видеоигр удовлетворяющих условиям поиска,
        /// хранящихся в соответствующийх полях объекта класса FilterOptions</returns>
        public List <VideoGame> GetGamesWithFilter(VideoGamesFilterQueryOptions filter)
        {
            var videoGames = GetVideoGamesList();

            if (filter.Title != null)
            {
                videoGames = videoGames.Where(p => p.Title.Contains(filter.Title));
            }
            ;
            if (filter.Price > 0)
            {
                videoGames = videoGames.Where(p => p.Price <= filter.Price);
            }
            ;
            if (filter.Platform > 0)
            {
                videoGames = videoGames.Where(p => p.Platform == filter.Platform);
            }
            ;

            if (filter.Genre <= 0)
            {
                return(videoGames.ToList());
            }
            var resilt = new List <VideoGame>();

            foreach (var game in videoGames)
            {
                if (game.Genre.Contains(filter.Genre))
                {
                    resilt.Add(game);
                }
            }

            return(resilt);
        }