1. 程式人生 > >通用分頁請求返回類

通用分頁請求返回類

color iquery 索引 using pre zed ron his 結束

using System.Runtime.Serialization;

    /// <summary>
    /// 通用分頁請求類
    /// </summary>
    [DataContract]
    public class PagedListModelReq : Request
    {
        /// <summary>
        /// <strong>Initializes a new instance of the <see cref="</strong>OperationLogReq<strong>
" /> class</strong> /// OperationLogReq /// </summary> public PagedListModelReq() { this.PageIndex = 1; this.PageSize = 15; } /// <summary> /// 索引開始 /// </summary> [DataMember] public int
StartIndex { get { int index = 0; if (this.PageSize > 0 && this.PageIndex > 0) { index = ((this.PageIndex - 1) * this.PageSize) + 1; } return index; } }
/// <summary> /// 索引結束 /// </summary> [DataMember] public int EndIndex { get { int index = 1; if (this.PageSize > 0 && this.PageIndex > 0) { index = this.PageIndex * this.PageSize; } return index; } } /// <summary> /// 分頁大小 /// </summary> [DataMember] public int PageSize { get; set; } /// <summary> /// 第幾頁數 /// </summary> [DataMember] public int PageIndex { get; set; } /// <summary> /// Called when [deserialized]. /// </summary> /// <param name="context">StreamingContext</param> [OnDeserialized] private void OnDeserialized(StreamingContext context) { if (this.PageIndex <= 0) { this.PageIndex = 1; } if (this.PageSize <= 0) { this.PageSize = 15; } } } /// <summary> /// 通用分頁請求類 /// </summary> /// <typeparam name="T">Poco類型</typeparam> [DataContract] public class PagedListModelReq<T> : Request { /// <summary> /// <strong>Initializes a new instance of the <see cref="</strong>OperationLogReq<strong>" /> class</strong> /// OperationLogReq /// </summary> public PagedListModelReq() { this.PageIndex = 1; this.PageSize = 15; } /// <summary> /// 索引開始 /// </summary> [DataMember] public int StartIndex { get { int index = 0; if (this.PageSize > 0 && this.PageIndex > 0) { index = ((this.PageIndex - 1) * this.PageSize) + 1; } return index; } } /// <summary> /// 索引結束 /// </summary> [DataMember] public int EndIndex { get { int index = 1; if (this.PageSize > 0 && this.PageIndex > 0) { index = this.PageIndex * this.PageSize; } return index; } } /// <summary> /// 分頁大小 /// </summary> [DataMember] public int PageSize { get; set; } /// <summary> /// 第幾頁數 /// </summary> [DataMember] public int PageIndex { get; set; } /// <summary> /// Called when [deserialized]. /// </summary> /// <param name="context">序列化的上下文</param> [OnDeserialized] private void OnDeserialized(StreamingContext context) { if (this.PageIndex <= 0) { this.PageIndex = 1; } if (this.PageSize <= 0) { this.PageSize = 15; } } }

    [Serializable]
    [DataContract]
    public class PagedResult<T> : IPagedResult<T>
    {
        protected PagedResult();
        public PagedResult(IList<T> source, int pageIndex, int pageSize);
        public PagedResult(IQueryable<T> source, int pageIndex, int pageSize);
        public PagedResult(IEnumerable<T> source, int pageIndex, int pageSize, int totalCount);

        [DataMember]
        public bool HasNextPage { get; }
        [DataMember]
        public bool HasPreviousPage { get; }
        [DataMember]
        public IEnumerable<T> Items { get; }
        [DataMember]
        public int PageIndex { get; }
        [DataMember]
        public int PageSize { get; }
        [DataMember]
        public int TotalCount { get; }
        [DataMember]
        public int TotalPages { get; }
    }

/// <summary>
    /// 通用分頁返回類
    /// </summary>
    /// <typeparam name="T">Model對應的類型</typeparam>
    [DataContract]
    public class PagedListModelResp<T> : Response
    {
        /// <summary>
        /// 返回分頁數據
        /// </summary>
        [DataMember]
        public PagedResult<T> List { get; set; }
    }

通用分頁請求返回類