public IActionResult Get(
            [FromQuery] AuthorSearch search,
            [FromServices] IGetAuthorsQuery query)
        {
            var result = _executor.ExecuteQuery(query, search);

            return(Ok(result));
        }
Пример #2
0
        public IQueryable <Book> filterbooks(IQueryable <Book> books, string searchstring, string author, string publisher)
        {
            var titlesearch = new TitleSearch();

            books = titlesearch.Result(books, searchstring);
            var authorsearch = new AuthorSearch();

            books = authorsearch.Result(books, author);
            var publishersearch = new PublisherSearch();

            books = publishersearch.Result(books, publisher);
            return(books);
        }
Пример #3
0
        public PagedResponse <AuthorDto> Execute(AuthorSearch search)
        {
            var query = _context.Authors.AsQueryable().DefaultFilter(search);

            if (!string.IsNullOrEmpty(search.FirstName) || !string.IsNullOrWhiteSpace(search.FirstName))
            {
                query = query.Where(x => x.FirstName.ToLower().Contains(search.FirstName.ToLower()));
            }

            if (!string.IsNullOrEmpty(search.LastName) || !string.IsNullOrWhiteSpace(search.LastName))
            {
                query = query.Where(x => x.LastName.ToLower().Contains(search.LastName.ToLower()));
            }

            return(query.Paged <AuthorDto, Domain.Author>(search, _mapper));
        }
Пример #4
0
        public PagedResponse <AuthorDto> Execute(AuthorSearch search)
        {
            var query = _context.Authors.Include(x => x.AuthorBooks)
                        .ThenInclude(b => b.Book)
                        //.ThenInclude(g => g.Genre)
                        .AsQueryable();

            if (!string.IsNullOrEmpty(search.FirstName) || !string.IsNullOrWhiteSpace(search.FirstName))
            {
                query = query.Where(x => x.FirstName.ToLower().Contains(search.FirstName.ToLower()));
            }



            var skipCount = search.PerPage * (search.Page - 1);

            var response = new PagedResponse <AuthorDto>
            {
                TotalCount   = query.Count(),
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                Items        = query.Skip(skipCount)
                               .Take(search.PerPage)
                               .Select(a => new AuthorDto
                {
                    Id         = a.Id,
                    FirstName  = a.FirstName,
                    LastName   = a.LastName,
                    Birth      = a.Birth,
                    BirthPlace = a.BirthPlace,

                    AuthorBooks = a.AuthorBooks.Select(ab => new AuthorBookDto
                    {
                        Id          = ab.BookId,
                        Description = ab.Book.Description,
                        Price       = ab.Book.Price,
                        Title       = ab.Book.Title,
                        Year        = ab.Book.Year,
                        Quantity    = ab.Book.Quantity
                    })
                })
            };

            return(response);
        }
Пример #5
0
        public PagedResponse <AuthorDto> Execute(AuthorSearch search)
        {
            var query = _context.Authors.AsQueryable();

            if (!string.IsNullOrEmpty(search.Author) || !string.IsNullOrWhiteSpace(search.Author))
            {
                query = query.Where(x => x.AuthorName.ToLower().Contains(search.Author.ToLower()));
            }
            var skipCount = search.PerPage * (search.Page - 1);
            var response  = new PagedResponse <AuthorDto>
            {
                CurrentPage  = search.Page,
                ItemsPerPage = search.PerPage,
                TotalCount   = query.Count(),
                Items        = query.Skip(skipCount).Take(search.PerPage).Select(x => new AuthorDto
                {
                    Id         = x.Id,
                    AuthorName = x.AuthorName
                }).ToList()
            };

            return(response);
        }
 public IActionResult Get([FromServices] IGetAuthors query, [FromQuery] AuthorSearch search)
 {
     return(Ok(_executor.ExecuteQuery(query, search)));
 }
Пример #7
0
 public PageResponse <AuthorDTO> Execute(AuthorSearch request)
 {
     throw new System.NotImplementedException();
 }