diff --git a/src/posts/CsPaginationTools.md b/src/posts/CsPaginationTools.md
index e761428..8a40355 100644
--- a/src/posts/CsPaginationTools.md
+++ b/src/posts/CsPaginationTools.md
@@ -32,21 +32,11 @@ namespace ASIS.Shared;
[DataContract(IsReference = true)]
public class PaginationOptions
{
- ///
- /// This constructor exists so that MVC can instantiate the object before mapping is contents
- ///
- public PaginationOptions() { }
-
- public PaginationOptions(int pageNumber, int? resultsPerPage)
- {
- this.PageNumber = pageNumber;
- this.ResultsPerPage = resultsPerPage;
- }
-
private int? _resultsPerPage;
private int _pageNumber;
/// The number of results per page
+ /// null for unlimited
[DataMember]
public int? ResultsPerPage
{
@@ -61,9 +51,7 @@ public class PaginationOptions
}
}
- ///
- /// The page number to get
- ///
+ /// The page number to get
/// One indexed
[DataMember]
public int PageNumber
@@ -78,8 +66,39 @@ public class PaginationOptions
this._pageNumber = value;
}
}
+
+ ///
+ /// This constructor exists so that MVC can instantiate the object before mapping is contents
+ ///
+ public PaginationOptions() { }
+
+ public PaginationOptions(int pageNumber, int? resultsPerPage)
+ {
+ this.PageNumber = pageNumber;
+ this.ResultsPerPage = resultsPerPage;
+ }
}
+///
+/// This exists because s can't be generic, so passing them an actual
+/// wouldn't work
+///
+public interface IPaginatedResults
+{
+ public int PageNumber { get; }
+ public int LastPageNumber { get; }
+ public int? ResultsPerPage { get; }
+ public int CurrentPageResultsCount { get; }
+ public int TotalResultsCount { get; }
+ public int FirstResultNumber { get; }
+ public int LastResultNumber { get; }
+ public bool IsFirstPage { get; }
+ public bool IsLastPage { get; }
+ public int PreviousPageNumber { get; }
+ public int NextPageNumber { get; }
+}
+
+
///
/// An extension of that contains the results from a query and uses
/// them to calculate additional pagination info
@@ -89,7 +108,7 @@ public class PaginationOptions
///
/// The data type of the results
[DataContract(IsReference = true)]
-public class PaginatedResults : PaginationOptions where T : class
+public class PaginatedResults : PaginationOptions, IPaginatedResults where T : class
{
[JsonConstructor]
public PaginatedResults(int pageNumber, int? resultsPerPage, IEnumerable results,
@@ -118,21 +137,21 @@ public class PaginatedResults : PaginationOptions where T : class
/// The number of results on the current page
///
[DataMember]
- public int? CurrentPageResultsCount { get => this.Results.Count(); }
+ public int CurrentPageResultsCount { get => this.Results.Count(); }
///
/// The number of the first result on the current page. This is calculated using
/// , , and .
///
[DataMember]
- public int? FirstResultNumber
+ public int FirstResultNumber
{
get
{
if (this.ResultsPerPage is null)
return 1;
- return (this.ResultsPerPage * (this.PageNumber - 1)) + 1;
+ return ((int)this.ResultsPerPage * (this.PageNumber - 1)) + 1;
}
}
@@ -141,14 +160,14 @@ public class PaginatedResults : PaginationOptions where T : class
/// , , and .
///
[DataMember]
- public int? LastResultNumber
+ public int LastResultNumber
{
get
{
if (this.ResultsPerPage is null)
return this.Results.Count();
- return (this.ResultsPerPage * (this.PageNumber - 1)) + this.CurrentPageResultsCount;
+ return ((int)this.ResultsPerPage * (this.PageNumber - 1)) + this.CurrentPageResultsCount;
}
}
@@ -157,15 +176,14 @@ public class PaginatedResults : PaginationOptions where T : class
///
///
[DataMember]
- public int? LastPageNumber
+ public int LastPageNumber
{
get
{
if (this.ResultsPerPage is null)
return 1;
- return (int)Math.Ceiling(this.TotalResultsCount
- / (double)this.ResultsPerPage);
+ return (int)Math.Ceiling(this.TotalResultsCount / (double)this.ResultsPerPage);
}
}
diff --git a/src/posts/PaginationTagHelpers.md b/src/posts/PaginationTagHelpers.md
index 6ccab03..716d4a1 100644
--- a/src/posts/PaginationTagHelpers.md
+++ b/src/posts/PaginationTagHelpers.md
@@ -27,28 +27,36 @@ The query parameter given as `page-number-key` will be changed or added to each
The `pager-details` tag helper:
```csharp
-using ASIS.SecretsManagement.Shared;
+using ASIS.Shared;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.TagHelpers;
using Microsoft.AspNetCore.Razor.TagHelpers;
using System.Text.Encodings.Web;
+namespace ASIS.Shared.TagHelpers;
+
///
/// Displays details about pagination in the form "Showing results x - y of z" on the left and
/// "Page x of y" on the right
///
-public class PagerDetailsTagHelper : TagHelper
+public class PaginationDetailsTagHelper : TagHelper
{
- public PaginatedResults