Exemplo n.º 1
0
        public Pagination <RoleDomain> GetPagination(string keyword, PageParams <RoleSort?> pageParams)
        {
            IQueryable <RoleInfo> query = _dc.RoleInfo;

            query = query.WhereHas(x => x.RoleName.Contains(keyword.Trim()));

            if (pageParams == null)
            {
                pageParams = PageParams <RoleSort?> .Unlimited();
            }

            bool isDesc = pageParams.Descending;

            try
            {
                query = query.OrderBy(pageParams.OrderField, isDesc);
            }
            catch (Exception)
            {
                query = query.OrderBy(x => x.RoleName, isDesc);
            }


            var result = query.AsPagination(pageParams.PageIndex, pageParams.PageSize);

            return(result.As(x => toDomain(x)));
        }
Exemplo n.º 2
0
        public Pagination <UserDomain> GetPagination(string keyword, PageParams <UserSort?> pageParams)
        {
            IQueryable <UserInfo> query = _dc.UserInfo;


            if (keyword.HasText())
            {
                keyword = keyword.Trim();

                query = query.Where(q =>
                                    q.Account.Contains(keyword) ||
                                    q.UserName.Contains(keyword) ||
                                    q.UserTitle.Contains(keyword)
                                    );
            }


            if (pageParams == null)
            {
                pageParams = PageParams <UserSort?> .Unlimited();
            }

            bool isDesc = pageParams.Descending;

            try
            {
                query = query.OrderBy(pageParams.OrderField, isDesc);
            }
            catch (Exception)
            {
                query = query.OrderBy(x => x.UserId, isDesc);
            }


            var result = query.AsPagination(pageParams.PageIndex, pageParams.PageSize);

            return(result.As(x => toDomain(x)));
        }