private PagedResponse <BookDto> Handle(ListBookFilteringQuery query) { var provider = DependencyInjectorStub.Get((s, c) => { BootStrapper.RegisterServices(s, c); s.AddScoped(x => MockRepository.GetContext()); }); var handler = provider.GetRequiredService <IRequestHandler <ListBookFilteringQuery, PagedResponse <BookDto> > >(); return(handler.Handle(query, CancellationToken.None).GetAwaiter().GetResult()); }
public async Task <PagedResponse <BookDto> > Handle(ListBookFilteringQuery request, CancellationToken cancellationToken) { var query = _db.Books.AsQueryable(); query = FilterQuery(query, request); return(await query.ToPagedResponseAsync(request, x => new BookDto { Id = x.Id, Title = x.Title, Author = x.AuthorName, Language = x.Language }, cancellationToken)); }
private static IQueryable <Entities.Book> FilterQuery(IQueryable <Entities.Book> query, ListBookFilteringQuery filter) { if (filter.Title != null) { query = query.Where(_ => _.Title == filter.Title); } if (filter.Category != null) { query = query.Where(_ => _.Categories.Any(c => c.Category.Name == filter.Category)); } if (filter.Language != null && filter.Language != Language.Unknown) { query = query.Where(_ => _.Language == filter.Language); } return(query); }
public async Task <IActionResult> GetAll([FromQuery] ListBookFilteringQuery query) { var result = await _mediator.Send(query); return(PagedOk(result)); }