Esempio n. 1
0
        public static List <LinkItem> CreateLinksForCollection(this IUrlHelper urlHelper, string methodName,
                                                               Criterion criterion, int totalCount)
        {
            var links = new List <LinkItem>();

            // self
            links.Add(
                new LinkItem(urlHelper.Link(methodName, new
            {
                pagecount = criterion.PageSize,
                page      = criterion.CurrentPage,
                orderby   = criterion.SortBy
            }), "self", "GET"));

            links.Add(new LinkItem(urlHelper.Link(methodName, new
            {
                pagecount = criterion.PageSize,
                page      = 1,
                orderby   = criterion.SortBy
            }), "first", "GET"));

            links.Add(new LinkItem(urlHelper.Link(methodName, new
            {
                pagecount = criterion.PageSize,
                page      = criterion.GetTotalPages(totalCount),
                orderby   = criterion.SortBy
            }), "last", "GET"));

            if (criterion.HasNext(totalCount))
            {
                links.Add(new LinkItem(urlHelper.Link(methodName, new
                {
                    pagecount = criterion.PageSize,
                    page      = criterion.CurrentPage + 1,
                    orderby   = criterion.SortBy
                }), "next", "GET"));
            }

            if (criterion.HasPrevious())
            {
                links.Add(new LinkItem(urlHelper.Link(methodName, new
                {
                    pagecount = criterion.PageSize,
                    page      = criterion.CurrentPage - 1,
                    orderby   = criterion.SortBy
                }), "previous", "GET"));
            }

            return(links);
        }
        private List <LinkItem> CreateLinksForCollection(Criterion criterion, int totalCount)
        {
            var links = new List <LinkItem>();

            // self
            links.Add(
                new LinkItem(_urlHelper.Link(nameof(GetAllProducts), new
            {
                pagecount = criterion.PageSize,
                page      = criterion.CurrentPage,
                orderby   = criterion.SortBy
            }), "self", "GET"));

            links.Add(new LinkItem(_urlHelper.Link(nameof(GetAllProducts), new
            {
                pagecount = criterion.PageSize,
                page      = 1,
                orderby   = criterion.SortBy
            }), "first", "GET"));

            links.Add(new LinkItem(_urlHelper.Link(nameof(GetAllProducts), new
            {
                pagecount = criterion.PageSize,
                page      = criterion.GetTotalPages(totalCount),
                orderby   = criterion.SortBy
            }), "last", "GET"));

            if (criterion.HasNext(totalCount))
            {
                links.Add(new LinkItem(_urlHelper.Link(nameof(GetAllProducts), new
                {
                    pagecount = criterion.PageSize,
                    page      = criterion.CurrentPage + 1,
                    orderby   = criterion.SortBy
                }), "next", "GET"));
            }

            if (criterion.HasPrevious())
            {
                links.Add(new LinkItem(_urlHelper.Link(nameof(GetAllProducts), new
                {
                    pagecount = criterion.PageSize,
                    page      = criterion.CurrentPage - 1,
                    orderby   = criterion.SortBy
                }), "previous", "GET"));
            }

            return(links);
        }