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)); }
public Task <IEnumerable <Book> > FindBooks(GetBooksFilter filter) => _bookStorage.FindBooks(filter);