public async Task <ActionResult <BooksResponseModel> > Get([FromQuery] PaginationParams model)
        {
            var response = new BooksResponseModel();
            var books    = await Task.FromResult(_context.Books.Where(x => !x.Excluded).OrderBy(x => x.Title).ToList());

            if (!string.IsNullOrEmpty(model.searchTerm))
            {
                books = books.Where(x =>
                                    x.Title.ToLower().Contains(model.searchTerm.ToLower()) ||
                                    x.Description.ToLower().Contains(model.searchTerm) ||
                                    x.Year.Contains(model.searchTerm)
                                    ).ToList();
            }
            if (books.Any())
            {
                response = ShowMensageResponse.BuildResponse(books, model);
            }
            else
            {
                response.Success = false;
            }


            return(Ok(response));
        }
Exemple #2
0
        public async Task <ActionResult <BooksResponseModel> > Get([FromQuery] bool flag, PaginationParams model)
        {
            var books = await Task.FromResult(_context.Books.Where(x => !x.Excluded).ToList());

            if (flag)
            {
                books = books.Where(x => x.Rented).ToList();
            }
            else
            {
                books = books.Where(x => !x.Rented).ToList();
            }
            var response = ShowMensageResponse.BuildResponse(books, model);

            if (!response.Success)
            {
                var notFound = new NotFoundResult();
                return(notFound);
            }

            return(Ok(response));
        }