Пример #1
0
        public HttpResponseMessage GetUserList(bool isDes = true, EnumUserOrderBy orderByAll = EnumUserOrderBy.OrderById, string userName = null, int page = 1, int pageSize = 10)
        {
            var userCondition = new UserSearchCondition
            {
                UserName = userName,
                Page = page,
                PageSize = pageSize,
                IsDescending = isDes,
                OrderBy = orderByAll

            };

            var userList = _userService.GetUserByCondition(userCondition).Select(a => new UserModel
            {
                Id = a.Id,
                UserName = a.UserName,
                Status = a.Status
            }).ToList();
            var userCount = _userService.GetUserCountByCondition(userCondition);
            return PageHelper.toJson(new { List = userList, Condition = userCondition, TotalCount = userCount });
        }
Пример #2
0
 public IQueryable<UserBase> GetUserByCondition(UserSearchCondition condition)
 {
     try
     {
         var query = _userRepository.Table;
         if (condition.BeginTime.HasValue)
         {
             query = query.Where(c => c.RegTime >= condition.BeginTime.Value);
         }
         if (condition.EndTime.HasValue)
         {
             query = query.Where(c => c.RegTime < condition.EndTime.Value);
         }
         if (condition.Status.HasValue)
         {
             query = query.Where(c => c.Status == condition.Status);
         }
         if (condition.Ids != null && condition.Ids.Length > 0)
         {
             query = query.Where(c => condition.Ids.Contains(c.Id));
         }
         if (!string.IsNullOrEmpty(condition.UserName))
         {
             query = query.Where(c => c.UserName.Contains(condition.UserName));
         }
         if (condition.OrderBy.HasValue)
         {
             switch (condition.OrderBy)
             {
                 case EnumUserOrderBy.Default:
                     query = condition.IsDescending
                         ? query.OrderByDescending(c => c.Id)
                         : query.OrderBy(c => c.Id);
                     break;
                 case EnumUserOrderBy.ById:
                     query = condition.IsDescending
                         ? query.OrderByDescending(c => c.Id)
                         : query.OrderBy(c => c.Id);
                     break;
                 case EnumUserOrderBy.ByName:
                     query = condition.IsDescending
                         ? query.OrderByDescending(c => c.UserName)
                         : query.OrderBy(c => c.UserName);
                     break;
                 case EnumUserOrderBy.RegTime:
                     query = condition.IsDescending
                         ? query.OrderByDescending(c => c)
                         : query.OrderBy(c => c.RegTime);
                     break;
                 case EnumUserOrderBy.OrderByStatus:
                     query = condition.IsDescending ? query.OrderByDescending(q => q.Status) : query.OrderBy(q => q.Status);
                     break;
             }
         }
         else
         {
             query = condition.IsDescending
                         ? query.OrderByDescending(c => c.Id)
                         : query.OrderBy(c => c.Id);
         }
         if (condition.Page.HasValue && condition.PageSize.HasValue)
         {
             query =
                 query.Skip((condition.Page.Value - 1) * condition.PageSize.Value).Take(condition.PageSize.Value);
         }
         return query;
     }
     catch (Exception e)
     {
         _log.Error(e, "获取用户列表失败");
         return null;
     }
 }
Пример #3
0
 public int GetUserCountByCondition(UserSearchCondition condition)
 {
     try
     {
         var query = _userRepository.Table;
         if (condition.BeginTime.HasValue)
         {
             query = query.Where(c => c.RegTime >= condition.BeginTime.Value);
         }
         if (condition.EndTime.HasValue)
         {
             query = query.Where(c => c.RegTime < condition.EndTime.Value);
         }
         if (condition.Status.HasValue)
         {
             query = query.Where(c => c.Status == condition.Status);
         }
         if (condition.Ids != null && condition.Ids.Length > 0)
         {
             query = query.Where(c => condition.Ids.Contains(c.Id));
         }
         if (!string.IsNullOrEmpty(condition.UserName))
         {
             query = query.Where(c => c.UserName.Contains(condition.UserName));
         }
         return query.Count();
     }
     catch (Exception e)
     {
         _log.Error(e, "获取用户列表失败");
         return -1;
     }
 }
Пример #4
0
        public HttpResponseMessage GetUserList(string userName=null,int page=1,int pageSize=10)
        {
            var userCondition = new UserSearchCondition
            {
                UserName = userName,
                Page = page,
                PageSize = pageSize
            };

            var userList = _userService.GetUserByCondition(userCondition).Select(a=>new UserModel
            {
                Id = a.Id,
                UserName = a.UserName,
                Status =a.Status
            }).ToList();
            var userCount = _userService.GetUserCountByCondition(userCondition);
            return PageHelper.toJson(new{ List=userList, Condition=userCondition, TotalCount=userCount});
        }