コード例 #1
0
        protected IEnumerable <LinkDto> CreateLinksForCollection <T>
            (PagedList <T> resources, IResourceParameters parameters)
            where T : AuditableEntity
        {
            var links             = new List <LinkDto>();
            var resourceUriHelper = new ResourceUriHelper(Url);
            var resourceUri       = pagination.CreateResourceUri
                                        (parameters, resourceUriHelper, ResourceUriType.Current);

            links.Add(new LinkDto(resourceUri, "self", "GET"));

            var pagesLinks = pagination.CreatePagesLinks(resources, parameters, resourceUriHelper);

            if (pagesLinks.HasPrevious)
            {
                links.Add(new LinkDto(pagesLinks.Previous, "previousPage", "GET"));
            }

            if (pagesLinks.HasNext)
            {
                links.Add(new LinkDto(pagesLinks.Next, "nextPage", "GET"));
            }

            return(links);
        }
コード例 #2
0
        public PagedList <Comment> GetAllComentsForPost
            (Guid postId, IResourceParameters parameters)
        {
            var comments = context.Comments
                           .Where(comment => postId == comment.PostId).AsNoTracking();

            if (!string.IsNullOrWhiteSpace(parameters.OrderBy))
            {
                comments = SortComments(comments, parameters.OrderBy);
            }

            return(PagedList <Comment> .Create
                       (comments, parameters.PageNumber, parameters.PageSize));
        }
コード例 #3
0
        public PagedList <Author> GetAllAuthors(IResourceParameters parameters)
        {
            var authors = context.Authors.AsNoTracking();

            return(PagedList <Author> .Create(authors, parameters.PageNumber, parameters.PageSize));
        }
コード例 #4
0
        protected dynamic GetCollectionWithLinks <T>(PagedList <T> resources,
                                                     IEnumerable <ExpandoObject> shapedResources, IResourceParameters parameters)
            where T : AuditableEntity
        {
            var ids = GetIds(resources).ToList();

            return(new
            {
                value = GetLinkedResources(shapedResources, ids, parameters.Fields),
                links = CreateLinksForCollection(resources, parameters)
            });
        }
コード例 #5
0
 private bool CantValidate(IResourceParameters parameters, bool fullMedia)
 {
     return(validator.DontMatchRules(parameters, ModelState) ||
            OrderIsInvalid(parameters.OrderBy, fullMedia) ||
            FieldsAreInvalid(parameters.Fields, fullMedia));
 }