public async Task <IActionResult> GetEndpointsAsync( [FromQuery] PagingOptions pagingOptions, [FromQuery] SortOptions <EndpointViewModel, EndpointEntity> sortOptions, [FromQuery] SearchOptions <EndpointViewModel, EndpointEntity> searchOptions, CancellationToken ct) { if (!ModelState.IsValid) { return(BadRequest(new ApiError(ModelState))); } pagingOptions.Offset = pagingOptions.Offset ?? _defaultPagingOptions.Offset; pagingOptions.Limit = pagingOptions.Limit ?? _defaultPagingOptions.Limit; var endpoints = await _endpointService.GetEndpointsByOwnerIdAsync(_userInfoService.UserId, pagingOptions, sortOptions, searchOptions, ct); /* What we get from data repository are endpoints, but what we want to return to users are endpoints view model. */ var endpointsViewModel = new PagedResults <EndpointViewModel>() { Items = Mapper.Map <IEnumerable <EndpointEntity>, IEnumerable <EndpointViewModel> >(endpoints.Items), TotalSize = endpoints.TotalSize }; var collection = PagedCollection <EndpointViewModel> .Create <EndpointsResponse>(Link.ToCollection(nameof(GetEndpointsAsync)), endpointsViewModel.Items.ToArray(), endpointsViewModel.TotalSize, pagingOptions); if (!Request.GetEtagHandler().NoneMatch(collection)) { return(StatusCode(304, collection)); } return(Ok(collection)); }