public async Task <ActionResult> GetTicketCategoriesAsync(Pagination pagination, SearchTicketCategory search) { // Mapping: TicketCategory var ticketCategoriesSource = await _unitOfWork.TicketCategories.GetAllAsync(); var ticketCategories = _mapper.Map <IEnumerable <TicketCategory>, IEnumerable <TicketCategoryDTO> >(ticketCategoriesSource); // Search by Name: if (search.Name != "") { ticketCategories = ticketCategories.Where(tc => tc.Name.ToLower().Contains(search.Name.ToLower())); } // Sort Asc: if (search.sortAsc != "") { ticketCategories = ticketCategories.OrderBy(tc => tc.GetType().GetProperty(search.sortAsc).GetValue(tc)); } // Sort Desc: if (search.sortDesc != "") { ticketCategories = ticketCategories.OrderByDescending(tc => tc.GetType().GetProperty(search.sortDesc).GetValue(tc)); } return(Ok(PaginatedList <TicketCategoryDTO> .Create(ticketCategories, pagination.current, pagination.pageSize))); }
public async Task <ActionResult> GetTicketCategoriesAsync([FromQuery] Pagination pagination, [FromQuery] SearchTicketCategory search) { var ticketCategories = await _service.GetTicketCategoriesAsync(pagination, search); return(ticketCategories); }