Example #1
0
        public async Task <Response <GetToursResponseDto> > GetAllTour(GetToursRequestDto requestDto)
        {
            var response = new Response <GetToursResponseDto>();;

            if (requestDto.Search == null)
            {
                requestDto.Search = string.Empty;
            }

            Predicate <Tour> filter = tour => true;

            if (requestDto.CountryId != 0 && requestDto.CityId == 0)
            {
                filter = tour => tour.CountrId == requestDto.CountryId;
            }

            if (requestDto.CountryId != 0 && requestDto.CityId != 0)
            {
                filter = tour => tour.CountrId == requestDto.CountryId && tour.CitId == requestDto.CityId;
            }

            Predicate <Tour> predicate = t => filter(t) && !t.isDeleted && t.Price > requestDto.Min && t.Price < requestDto.Max && t.Name.Contains(requestDto.Search);
            var count = await _unitOfWork
                        .TourRepository
                        .Count(tour => predicate(tour));

            int skip = (requestDto.Page - 1) * requestDto.Size;

            var listTour = await _unitOfWork.TourRepository.Get(tour => predicate(tour), skip, requestDto.Size, tour => tour.FileModels);

            var responseList = new List <ToursRespoonse>();

            foreach (var elem in listTour)
            {
                var item = new ToursRespoonse
                {
                    Id    = elem.Id,
                    Name  = elem.Name,
                    Price = elem.Price,
                    Path  = elem.FileModels.FirstOrDefault()?.Path
                };
                responseList.Add(item);
            }

            response.Data = new GetToursResponseDto()
            {
                Count    = count,
                ListTour = responseList
            };
            return(response);
        }
Example #2
0
        public async Task <IActionResult> GetAllTour([FromQuery] GetToursRequestDto requestDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var response = await _tourService.GetAllTour(requestDto);

            if (response.Error != null)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }