Пример #1
0
 /// <summary>
 /// Create the HATEOAS links for allowable hyperlink actions via HTTP navigation
 /// </summary>
 /// <param name="vectorWrapper">the containing wrapper class that has a value and links section</param>
 /// <param name="reqParams">the pagination request parameters from the http header</param>
 /// <returns>the existing nodeList entry plus the allowable links</returns>
 private Models.LinkedCollectionWrapperDto <Models.VectorWithLinksDto> CreateLinksForNodeVectorList(
     Models.LinkedCollectionWrapperDto <Models.VectorWithLinksDto> vectorWrapper,
     DataRequestParams reqParams)
 {
     vectorWrapper.Links.Add(new Models.LinkDto(
                                 _urlHelper.Link("GetVectorsForNode", new {}),
                                 "self",
                                 "GET"
                                 ));
     // next page
     vectorWrapper.Links.Add(new Models.LinkDto(
                                 CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.Next),
                                 "next_page",
                                 "GET"
                                 ));
     // previous page
     vectorWrapper.Links.Add(new Models.LinkDto(
                                 CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.Previous),
                                 "previous_page",
                                 "GET"
                                 ));
     // current page
     vectorWrapper.Links.Add(new Models.LinkDto(
                                 CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.None),
                                 "current_page",
                                 "GET"
                                 ));
     return(vectorWrapper);
 }
Пример #2
0
        public async Task <IActionResult> GetVectorsForNode(int nodeId,
                                                            DataRequestParams reqParams,
                                                            [FromHeader(Name = "Accept")] string mediaType)
        {
            var nodeVectors = await _vectorRepo.SelectVectorsByNodeAsync(nodeId, reqParams);

            if (nodeVectors == null)
            {
                return(NotFound());
            }

            if (mediaType == "application/unionall+json")
            {
                var providedVectors = Mapper.Map <IEnumerable <VectorWithLinksDto> >(nodeVectors);

                // add the HATEOAS links for each vectorDTO
                providedVectors = providedVectors.Select(vector =>
                {
                    vector = CreateLinksForVector(vector);
                    return(vector);
                });

                var wrapper = new Models.LinkedCollectionWrapperDto <VectorWithLinksDto>(providedVectors);
                return(Ok(CreateLinksForNodeVectorList(wrapper, reqParams)));
            }
            else
            {
                // add the pagination links
                Response.Headers.Add("LinkCurrent", CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.None));
                Response.Headers.Add("LinkPrevious", CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.Previous));
                Response.Headers.Add("LinkNext", CreateNavLink("GetVectorsForNode", reqParams, UrlNavigationType.Next));

                var providedVectors = Mapper.Map <IEnumerable <VectorDto> >(nodeVectors);

                return(Ok(providedVectors));
            }
        }