public IHttpActionResult SearchTour([FromBody] TourSearchRequestDto request)
        {
            if (request.MinPrice > request.MaxPrice)
            {
                return(BadRequest("MinPrice must be less than MaxPrice"));
            }

            var query = context.Tours.AsQueryable();

            query = query.Where(i => i.Price <= request.MaxPrice &&
                                i.Price >= request.MinPrice);

            return(Ok(query.ToList()));
        }
Exemplo n.º 2
0
        public List <Tour> SearchTours([FromBody] TourSearchRequestDto request)
        {
            if (request.MinPrice > request.MaxPrice)
            {
                throw new HttpResponseException(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Content    = new StringContent("MinPrice must be less than MaxPrice.")
                });
            }

            var query = _context.Tours.AsQueryable()
                        .Where(i => i.Price >= request.MinPrice && i.Price <= request.MaxPrice);

            return(query.ToList());
        }