public async Task <PagedList <RouteSearchResultDto> > SearchRouteAsync(RouteSearchDto routeParams)
        {
            var results = await(from r in this.context.Routes
                                where r.SourceAirportId == routeParams.SourceAirportId && r.DestinationAirportId == routeParams.DestinationAirportId
                                join a1 in this.context.Airports on r.SourceAirportId equals a1.AirportId
                                join a2 in this.context.Airports on r.DestinationAirportId equals a2.AirportId
                                join al in this.context.Airlines on r.AirlineID equals al.AirlineId
                                select new RouteIndex
            {
                RouteId                   = r.RouteId,
                FlightFare                = r.FlightFare,
                DepartureDateTime         = r.DepartureDateTime,
                ArrivalDateTime           = r.ArrivalDateTime,
                SourceAirportName         = a1.AirportName,
                SourceAirportId           = a1.AirportId,
                SourceAirportCity         = a1.City,
                SourceAirportCountry      = a1.Country,
                DestinationAirportName    = a2.AirportName,
                DestinationAirportId      = a2.AirportId,
                DestinationAirportCity    = a2.City,
                DestinationAirportCountry = a2.Country,
                AirlineName               = al.AirlineName,
                SourceLat                 = a1.Lat,
                SourceLon                 = a1.Lon,
                DestinationLat            = a2.Lat,
                DestinationLon            = a2.Lon
            }).ToListAsync();


            var routeResults = this.mapper.Map <List <RouteSearchResultDto> >(results);

            var resultSet = PagedList <RouteSearchResultDto> .Create(routeResults.AsQueryable(), routeParams.PageNumber, routeParams.PageSize);

            return(resultSet);
        }
        public async Task <PagedList <RouteSearchResultDto> > SearchAllRouteAsync(RouteSearchDto routeParams)
        {
            /*
             * Actually I don't have to create new instance of RouteIndex in this test project.
             * But in real scenario I recommend that you split with model and dto using some mapper to instantiate from model to dto.
             */
            var results = await(from r in this.context.Routes
                                join a1 in this.context.Airports on r.SourceAirportId equals a1.AirportId
                                join a2 in this.context.Airports on r.DestinationAirportId equals a2.AirportId
                                join al in this.context.Airlines on r.AirlineID equals al.AirlineId
                                select new RouteIndex
            {
                RouteId                   = r.RouteId,
                FlightFare                = r.FlightFare,
                DepartureDateTime         = r.DepartureDateTime,
                ArrivalDateTime           = r.ArrivalDateTime,
                SourceAirportName         = a1.AirportName,
                SourceAirportId           = a1.AirportId,
                SourceAirportCity         = a1.City,
                SourceAirportCountry      = a1.Country,
                DestinationAirportName    = a2.AirportName,
                DestinationAirportId      = a2.AirportId,
                DestinationAirportCity    = a2.City,
                DestinationAirportCountry = a2.Country,
                AirlineName               = al.AirlineName,
                SourceLat                 = a1.Lat,
                SourceLon                 = a1.Lon,
                DestinationLat            = a2.Lat,
                DestinationLon            = a2.Lon
            }).ToListAsync();

            var routeResults = this.mapper.Map <List <RouteSearchResultDto> >(results);

            return(PagedList <RouteSearchResultDto> .Create(routeResults.AsQueryable(), routeParams.PageNumber, routeParams.PageSize));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SearchAllRoute([FromQuery] RouteSearchDto routeParams)
        {
            var routeSearchResults = await this.searchMemoryRepository.SearchAllRouteAsync(routeParams);

            Response.AddPagination(routeSearchResults.CurrentPage, routeSearchResults.PageSize, routeSearchResults.TotalCount, routeSearchResults.TotalPages);
            return(Ok(routeSearchResults));
        }
Exemplo n.º 4
0
        public async Task <List <RouteSearchResultDto> > SearchRouteAsync(RouteSearchDto routeParams)
        {
            var foundRouteIndexes = await this.elasticClient.SearchAsync <RouteIndex>(searchDescriptor => searchDescriptor
                                                                                      .Query(queryContainerDescriptor => queryContainerDescriptor
                                                                                             .Bool(queryDescriptor => queryDescriptor
                                                                                                   .Must(queryStringQuery => queryStringQuery
                                                                                                         .QueryString(queryString => queryString
                                                                                                                      .Query(routeParams.FullTextSearch)))))
                                                                                      .From((routeParams.PageNumber - 1) * routeParams.PageSize)
                                                                                      .Size(routeParams.PageSize));

            var resultSet = this.mapper.Map <List <RouteSearchResultDto> >(foundRouteIndexes.Documents);

            return(PagedList <RouteSearchResultDto> .Create(resultSet.AsQueryable(), routeParams.PageNumber, routeParams.PageSize));
        }
        public async Task <IActionResult> SearchRoute([FromQuery] RouteSearchDto routeParams)
        {
            var routeSearchResults = await this.searchElasticRepository.SearchRouteAsync(routeParams);

            return(Ok(routeSearchResults));
        }