示例#1
0
        public object GetShapedCollectionWithLinks(PagedList <Performance> performances,
                                                   ResourceParameters resourceParameters)
        {
            var shapedPerformances = _mapper.Map <IEnumerable <PerformanceDto> >(performances)
                                     .ShapeData(resourceParameters.Fields);

            var shapedPerformancesWithLinks = shapedPerformances.Select(performance =>
            {
                var performanceAsDictionary = performance as IDictionary <string, object>;
                var performanceLinks        = _paginationService.CreateLinksForEntity((Guid)performanceAsDictionary["Id"], null);
                performanceAsDictionary.Add("links", performanceLinks);
                return(performanceAsDictionary);
            });

            return(new
            {
                value = shapedPerformancesWithLinks,
                links = _paginationService.CreateLinksForEntities(resourceParameters, performances.HasNext, performances.HasPrevious)
            });
        }
示例#2
0
        private object GetCustomShapedCollection(PagedList <Skill> skills, ResourceParameters resourceParameters, MediaTypeHeaderValue parsedMediaType)
        {
            var shapedSkills = _mapper.Map <IEnumerable <SkillDto> >(skills)
                               .ShapeData(resourceParameters.Fields);

            if (_paginationService.IncludeLinks(parsedMediaType))
            {
                var shapedSkillsWithLinks = shapedSkills.Select(skill =>
                {
                    var skillAsDictionary = skill as IDictionary <string, object>;
                    var skillLinks        = _paginationService.CreateLinksForEntity((Guid)skillAsDictionary["Id"], null);
                    skillAsDictionary.Add("links", skillLinks);
                    return(skillAsDictionary);
                });

                return(new
                {
                    value = shapedSkillsWithLinks,
                    links = _paginationService.CreateLinksForEntities(resourceParameters, skills.HasNext, skills.HasPrevious)
                });
            }

            return(shapedSkills);
        }