private ILink GetPreviousLink(int size, int offset, int limit)
        {
            if (offset == 0)
            {
                return(null);
            }

            if (offset > size)
            {
                return(GetLastLink(size, limit));
            }

            var previousPage = Math.Max(offset - limit, 0);

            if (previousPage <= 0)
            {
                return(GetFirstLink());
            }

            var newLink = new PlaceholderLink(_meta);

            newLink.Values.Add("limit", limit);
            newLink.Values.Add("offset", previousPage);

            return(newLink);
        }
Exemplo n.º 2
0
 public RootModel()
 {
     Meta = new PlaceholderLink()
     {
         Href   = "/",
         Method = "GET"
     };
 }
Exemplo n.º 3
0
        public Form(string path, string method, string relation, IEnumerable <FormField> fields)
        {
            Meta = new PlaceholderLink
            {
                Href      = path,
                Method    = method,
                Relations = new[] { relation }
            };

            Items = fields.ToArray();
        }
        private ILink GetNextLink(int size, int offset, int limit)
        {
            var nextPage = offset + limit;

            if (nextPage >= size)
            {
                return(null);
            }

            var newLink = new PlaceholderLink(_meta);

            newLink.Values.Add("limit", limit);
            newLink.Values.Add("offset", nextPage);

            return(newLink);
        }
        private ILink GetLastLink(int size, int limit)
        {
            if (size <= limit)
            {
                return(GetFirstLink());
            }

            var offset = Math.Ceiling((size - (double)limit) / limit) * limit;

            var newLink = new PlaceholderLink(_meta);

            newLink.Values.Add("limit", limit);
            newLink.Values.Add("offset", offset);

            return(newLink);
        }