public IActionResult GetDestinationCollection( [ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids) { if (ids == null) { return(BadRequest()); } var destinationEntities = _tripInfoRepository.GetDestinations(ids); if (ids.Count() != destinationEntities.Count()) { return(NotFound()); } var destinationsToReturn = Mapper.Map <IEnumerable <DestinationDto> >(destinationEntities); return(Ok(destinationsToReturn)); }
public IActionResult GetDestinations(DestinationsResourceParameters destinationsResourceParameters) { if (!_propertyMappingService.ValidMappingExistsFor <DestinationDto, Destination> (destinationsResourceParameters.OrderBy)) { return(BadRequest()); } if (!_typeHelperService.TypeHasProperties <DestinationDto> (destinationsResourceParameters.Fields)) { return(BadRequest()); } var destinationsFromRepo = _tripInfoRepository.GetDestinations(destinationsResourceParameters); var previousPageLink = destinationsFromRepo.HasPrevious ? CreateDestinationsResourceUri(destinationsResourceParameters, ResourceUriType.PreviousPage) : null; var nextPageLink = destinationsFromRepo.HasNext ? CreateDestinationsResourceUri(destinationsResourceParameters, ResourceUriType.NextPage) : null; var paginationMetadata = new { totalCount = destinationsFromRepo.TotalCount, pageSize = destinationsFromRepo.PageSize, currentPage = destinationsFromRepo.CurrentPage, totalPages = destinationsFromRepo.TotalPages, previousPageLink = previousPageLink, nextPageLink = nextPageLink }; Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata)); var destinations = Mapper.Map <IEnumerable <DestinationDto> >(destinationsFromRepo); return(Ok(destinations.ShapeData(destinationsResourceParameters.Fields))); }