public Pagination(IEnumerable <T> items, int totalItems, IPaginationSetting settings) { if (items == null) { throw new ArgumentNullException(nameof(items)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } var page = settings.Page; var pageSize = settings.PageSize; if (page < 1) { throw new ArgumentOutOfRangeException("page", page, "Value must be greater than zero."); } if (pageSize < 1) { throw new ArgumentOutOfRangeException("page", page, "Value must be greater than zero."); } if (totalItems < 0) { throw new ArgumentOutOfRangeException("page", page, "Value cannot be less than zero."); } this.items = items.ToList(); this.Page = page; this.PageSize = pageSize; this.TotalItems = totalItems; }
public ListTODOResponse(IEnumerable <TodoEntity> items, int totalItems, IPaginationSetting settings) : base(items, totalItems, settings) { }
public static Pagination <T> AsPagination <T>(this IQueryable <T> query, IPaginationSetting settings) { var results = query.Skip((settings.Page - 1) * settings.PageSize).Take(settings.PageSize); return(new Pagination <T>(results, query.Count(), settings)); }