Example #1
0
        public async Task <IActionResult> GetByIdAsync(int id)
        {
            var querySet = _jsonApiBuilder.BuildQuerySet(HttpContext.Request.Query);

            var building = await _buildingManager.GetByIdAsync(id, querySet);

            var buildingDto = _mapper.Map <BuildingDto>(building, opt => opt.Items["include"] = querySet.Include);
            var included    = _includedCollector.CollectIncluded(building, querySet.Include);
            var links       = _jsonApiBuilder.BuildSingleResourceLinks(HttpContext.Request.Path, querySet);

            return(Ok(new ResourceResponse()
            {
                Links = links, Data = buildingDto, Included = included
            }));
        }
Example #2
0
        public async Task <IActionResult> GetAllAsync()
        {
            var querySet = _jsonApiBuilder.BuildQuerySet(HttpContext.Request.Query);

            var pagedRequests = await _requestManager.GetAllAsync(querySet);

            var requestDtos = _mapper.Map <IEnumerable <RequestDto> >(pagedRequests.Items, opt => opt.Items["include"] = querySet.Include);
            var included    = _includedCollector.CollectIncluded(pagedRequests.Items, querySet.Include);
            var links       = _jsonApiBuilder.BuildCollectionLinks(HttpContext.Request.Path, querySet, pagedRequests);
            var meta        = _jsonApiBuilder.BuildCollectionMetadata(pagedRequests);

            return(Ok(new ResourceResponse()
            {
                Meta = meta, Links = links, Data = requestDtos, Included = included
            }));
        }