Skip to content

CQRS : Add PaginatedResult<T>  #203

Open

Description

@IncodingSoftware
    public class PaginatedResult<T>
    {
        public PaginatedResult(List<T> res, int totalCount, int pageSize, int currentPage)
        {
            Items = res;
            TotalCount = totalCount;
            var remainder = 0;
            var pageCount =  pageSize == 0 ? 0 :  Math.DivRem(totalCount, pageSize, out remainder);
            if (remainder > 0 || pageCount == 0)
                ++pageCount;

            PageCount = pageCount;
            CurrentPage = currentPage;
            From = currentPage == 1 ? 1 : pageSize * (currentPage - 1);
            To = currentPage == 1 ? res.Count : From + res.Count;
        }

        public int CurrentPage { get; set; }

        public List<T> Items { get; set; }

        public int TotalCount { get; set; }

        public int PageCount { get; set; }

        public int From { get; set; }

        public int To { get; set; }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions