Ejemplo n.º 1
0
        public async Task <ActionResult> GetAirlinesAsync([FromQuery] Pagination pagination, [FromQuery] SearchAirline search)
        {
            // Mapping: Airline
            var airlinesSource = await _unitOfWork.Airlines.GetAllAsync();

            var airlines = _mapper.Map <IEnumerable <Airline>, IEnumerable <AirlineDTO> >(airlinesSource);

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

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

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

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

            return(Ok(PaginatedList <AirlineDTO> .Create(airlines, pagination.current, pagination.pageSize)));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> GetAirlinesAsync([FromQuery] Pagination pagination, [FromQuery] SearchAirline search)
        {
            var airlines = await _service.GetAirlinesAsync(pagination, search);

            return(airlines);
        }