示例#1
0
        public async Task <IActionResult> SearchCardsByName([FromQuery] MagicCardQueryParams searchParams)
        {
            var cards = await _cardContext.GetCards(searchParams);

            if (cards == null || cards.Count == 0)
            {
                return(NoContent());
            }
            return(Ok(cards));
        }
        public async Task <List <MagicCard> > GetCards(MagicCardQueryParams parameters)
        {
            var predicate = _dbContext.MagicCards.Where(x => true);

            if (!string.IsNullOrEmpty(parameters.SetCode))
            {
                predicate = predicate.Where(x => x.SetCode == parameters.SetCode);
            }
            if (!string.IsNullOrEmpty(parameters.CardName))
            {
                predicate = predicate.Where(x => x.CardName.ToLower().Contains(parameters.CardName.ToLower()));
            }
            if (!string.IsNullOrEmpty(parameters.Language))
            {
                predicate = predicate.Where(x => x.Language == parameters.Language);
            }

            return(await predicate.ToListAsync());
        }