Esempio n. 1
0
        public async Task <ActionResult> GetAirportsAsync(Pagination pagination, SearchAirport search)
        {
            // Mapping: Airport
            var airportsSource = await _unitOfWork.Airports.GetAllAsync();

            var airports = _mapper.Map <IEnumerable <Airport>, IEnumerable <AirportDTO> >(airportsSource);

            // Search by Id:
            if (!string.IsNullOrEmpty(search.Id))
            {
                airports = airports.Where(a =>
                                          a.Id.ToLower().Contains(search.Id.ToLower()));
            }

            // Search by Name:
            if (!string.IsNullOrEmpty(search.Name))
            {
                airports = airports.Where(a =>
                                          a.Name.ToLower().Contains(search.Name.ToLower()));
            }

            // Search by Location:
            if (!string.IsNullOrEmpty(search.Location))
            {
                airports = airports.Where(a =>
                                          a.Location.ToLower().Contains(search.Location.ToLower()));
            }

            // Search by Id:
            if (!string.IsNullOrEmpty(search.Id))
            {
                airports = airports.Where(a =>
                                          a.Id.ToLower().Contains(search.Id.ToLower()));
            }

            // Sort Asc:
            if (!string.IsNullOrEmpty(search.sortAsc))
            {
                airports = airports.OrderBy(a =>
                                            a.GetType().GetProperty(search.sortAsc).GetValue(a));
            }

            // Sort Desc:
            if (!string.IsNullOrEmpty(search.sortDesc))
            {
                airports = airports.OrderByDescending(a =>
                                                      a.GetType().GetProperty(search.sortDesc).GetValue(a));
            }

            return(Ok(PaginatedList <AirportDTO> .Create(airports, pagination.current, pagination.pageSize)));
        }
Esempio n. 2
0
        public async Task <ActionResult> GetAirportsAsync([FromQuery] Pagination pagination, [FromQuery] SearchAirport search)
        {
            var airports = await _service.GetAirportsAsync(pagination, search);

            return(airports);
        }