예제 #1
0
        public async Task <IEnumerable <Book> > FindBooks(GetBooksFilter filter)
        {
            using var context = _contextFactory.CreateDbContext();
            var query = context.Books.Include(x => x.Author).AsQueryable();

            if (!string.IsNullOrEmpty(filter.Author))
            {
                query = query.Where(x => EF.Functions.Like(x.Author.Name, $"%{filter.Author}%"));
            }

            if (!string.IsNullOrEmpty(filter.BookName))
            {
                query = query.Where(x => EF.Functions.Like(x.Name, $"%{filter.BookName}%"));
            }

            var dbBooks = await query.ToArrayAsync();

            return(_mapper.Map <IEnumerable <Book> >(dbBooks));
        }
예제 #2
0
 public Task <IEnumerable <Book> > FindBooks(GetBooksFilter filter) => _bookStorage.FindBooks(filter);