src/Herobook/App_Start/Hypermedia/Hal.cs
/// <summary>Generate a hypermedia links object containing first/final/prev/next links for paging through datasets.</summary>
/// <param name="path">The absolute URL path to be decorated with paging querystring parameters</param>
/// <param name="index">The index of the first record on the current page</param>
/// <param name="count">The count of items on each page</param>
/// <param name="total">The total number of items in the collection</param>
/// <returns></returns>
Generate a hypermedia links object containing first/final/prev/next links for paging through datasets.
Generate a hypermedia links object containing first / final / prev / next links for paging through datasets .
public static dynamic Paginate(string path, int index, int count, int total) {
            dynamic _links = new ExpandoObject();
            var maxIndex = total - 1;
            _links.first = Href($"{path}?index=0");
            _links.final = Href($"{path}?index={maxIndex - maxIndex % count}");
            if (index > 0) _links.previous = Href($"{path}?index={index - count}");
            if (index + count < maxIndex) _links.next = Href($"{path}?index={index + count}");
            return _links;
        }
public static dynamic Paginate ( string path , int index , int count , int total ) { dynamic _links = new ExpandoObject ( ) ; var maxIndex = total - 1 ; _links . first = Href ( $" { path } ?index=0 " ) ; _links . final = Href ( $" { path } ?index= { maxIndex - maxIndex % count } " ) ; if ( index > 0 ) _links . previous = Href ( $" { path } ?index= { index - count } " ) ; if ( index + count < maxIndex ) _links . next = Href ( $" { path } ?index= { index + count } " ) ; return _links ; }
Generate a hypermedia links object containing first/final/prev/next links for paging through datasets.
Generate a hypermedia links object containing first / final / prev / next links for paging through datasets .
None
path
string
The absolute URL path to be decorated with paging querystring parameters
The absolute URL path to be decorated with paging querystring parameters
index
int
The index of the first record on the current page
The index of the first record on the current page
count
int
The count of items on each page
The count of items on each page
total
int
The total number of items in the collection
The total number of items in the collection