Ejemplo n.º 1
0
    public virtual List <T> GetPageList(string queryJson, PageModel pageModel, string orderby = null)
    {
        List <IConditionalModel> conditionalModels = new List <IConditionalModel>();

        if (!string.IsNullOrEmpty(queryJson))
        {
            var condtions = JToken.Parse(queryJson).Children <JProperty>();
            if (condtions.Any())
            {
                List <string> propertyNames = typeof(T).GetProperties().Select(t => t.Name).ToList();
                foreach (JProperty item in condtions)
                {
                    if (propertyNames.Contains(item.Name))
                    {
                        conditionalModels.Add(new ConditionalModel()
                        {
                            ConditionalType = ConditionalType.Like,
                            FieldName       = item.Name,
                            FieldValue      = item.Value.ToString()
                        });
                    }
                }
            }
        }
        int  total     = 0;
        bool isorderby = !string.IsNullOrEmpty(orderby);
        var  result    = CurrentDb.AsQueryable().Where(conditionalModels).OrderByIF(isorderby, orderby).ToPageList(pageModel.PageIndex, pageModel.PageSize, ref total);

        pageModel.PageCount = total;
        return(result);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 分页
 /// </summary>
 /// <param name="pageIndex"></param>
 /// <param name="pageSize"></param>
 /// <returns></returns>
 public async Task <Tuple <List <TEntity>, int, int> > PageList(int pageIndex, int pageSize)
 {
     return(await Task.Run(() =>
     {
         int totalNumber = 0;
         int totalPage = 0;
         var data = CurrentDb.AsQueryable().ToPageList(pageIndex, pageSize, ref totalNumber, ref totalPage);
         return new Tuple <List <TEntity>, int, int>(data, totalNumber, totalPage);
     }));
 }
Ejemplo n.º 3
0
 public async Task <User> CheckLogin(string userName, string passWord)
 {
     return(await CurrentDb.AsQueryable().SingleAsync(i => i.UserName == userName && i.PassWord == passWord));
 }