示例#1
0
        public async Task <ActionResult <BookToReturnDto> > GetBook(int id)
        {
            var spec = new BooksWithAuthorsAndCatsSpecification(id);

            var book = await _bookRepo.GetEntityWithSpecification(spec);

            return(_mapper.Map <Book, BookToReturnDto>(book));
        }
示例#2
0
        public async Task <ActionResult <IReadOnlyList <BookToReturnDto> > > GetBooksAsync(
            [FromQuery] string sort, int?authorId, int?catId)
        {
            //lesson in here: if you use searchparam or bookParams, u've to use them all...
            //else, using others directly and search as an object will not work
            //also, if u use bookParams, u have to declare [fromQuery]
            var spec = new BooksWithAuthorsAndCatsSpecification(sort, authorId, catId);

            var books = await _bookRepo.GetAllWithSpecification(spec);

            return(Ok(_mapper.Map <IReadOnlyList <Book>, IReadOnlyList <BookToReturnDto> >(books)));
        }