Exemplo n.º 1
0
        public async Task <CollectionResult <ReservedBookDto> > SearchReservedBooks(ReservedBookSearchDto model)
        {
            var result = new CollectionResult <ReservedBookDto>();

            var entities = _reservedBookRepository
                           .Get()
                           .WhereIf(model.UserId != null, item => item.UserId == model.UserId)
                           .WhereIf(model.Genre != null, item => item.AvailableBook.Book.Genre == model.Genre)
                           .WhereIf(model.Condition != null, item => item.AvailableBook.Book.Condition == model.Condition)
                           .WhereIf(!string.IsNullOrEmpty(model.SearchString),
                                    x => x.AvailableBook.Book.Name.ToLower().Contains(model.SearchString.ToLower()) ||
                                    x.AvailableBook.Book.Author.ToLower().Contains(model.SearchString.ToLower()) ||
                                    x.User.FirstName.ToLower().Contains(model.SearchString.ToLower()) ||
                                    x.User.LastName.ToLower().Contains(model.SearchString.ToLower()) ||
                                    x.User.Email.ToLower().Contains(model.SearchString.ToLower()))
                           .Include(x => x.AvailableBook)
                           .ThenInclude(x => x.Book)
                           .AsQueryable();

            var searchResult = await entities.ToListAsync();

            if (searchResult != null)
            {
                result.Items        = _mapper.Map <List <ReservedBook>, List <ReservedBookDto> >(searchResult);
                result.IsSuccessful = true;
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SearchReservedBooks([FromBody] ReservedBookSearchDto model)
        {
            var result = await _reservedBookService.SearchReservedBooks(model);

            return(new OkObjectResult(result));
        }