Ejemplo n.º 1
0
        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <param name="count">记录数</param>
        /// <returns></returns>
        public List<ProductOrderEntity> GetPaged(ProductOrderQuery query, out int count)
        {
            List<ProductOrderEntity> list = null;
            var conn = SessionFactory.CreateConnection();

            try
            {
                var sortList = new List<DapperExtensions.ISort>();
                sortList.Add(new DapperExtensions.Sort { PropertyName = "ID", Ascending = false });

                IFieldPredicate predicate = null;
                if (query.Status > 0){
                    predicate = Predicates.Field<ProductOrderEntity>(f => f.Status, Operator.Eq, query.Status);
                }
                else if (!string.IsNullOrEmpty(query.RoleCode))
                {
                    var status = GetStatusByRoleCode(query.RoleCode);
                    if (status < 6)
                        predicate = Predicates.Field<ProductOrderEntity>(f => f.Status, Operator.Eq, status);
                    else
                        predicate = Predicates.Field<ProductOrderEntity>(f => f.Status, Operator.Ge, status);
                }

                count = QuickRepository.Count<ProductOrderEntity>(conn, predicate);
                list = QuickRepository.GetPaged<ProductOrderEntity>(conn, query.PageIndex, query.PageSize,
                    predicate, sortList, false).ToList();

                return list;
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
 public ResponseResult<List<ProductOrderEntity>> QueryPaged(ProductOrderQuery query)
 {
     var result = ResponseResult<List<ProductOrderEntity>>.Default();
     var conn = SessionFactory.CreateConnection();
     try
     {
         var count = 0;
         var list = ProductOrderService.GetPaged(query, out count);
         result = ResponseResult<List<ProductOrderEntity>>.Success(list);
         result.TotalRowsCount = count;
         result.TotalPages = (count + query.PageSize - 1) / query.PageSize;
     }
     catch (System.Exception ex)
     {
         result = ResponseResult<List<ProductOrderEntity>>.Error(
             string.Format("获取{0}分页数据失败,错误{1}", "ProductOrder", ex.Message)
         );
     }
     return result;
 }