Example #1
0
 public List <AccountModel.SmallModel> GetAccountList(AccountModel.Search search)
 {
     using (var dbScope = _dbScopeFactory.Create())
     {
         var db    = dbScope.DbContexts.Get <WebDbContext>();
         var query = from p in db.SysAccounts
                     where (string.IsNullOrEmpty(search.SearchKey) ? true : p.RealName.Contains(search.SearchKey)) && ((search.usertype == null || search.usertype == 0)? true : p.UserType == search.usertype)
                     select new AccountModel.SmallModel {
             Id       = p.Id,
             RealName = p.RealName,
             UserType = p.UserType
         };
         return(query.ToList());
     }
 }
Example #2
0
        /// <summary>
        /// 获取用户分页列表
        /// </summary>
        /// <param name="pager"></param>
        /// <param name="search"></param>
        /// <param name="studented">只获取学生类型的</param>
        /// <returns></returns>
        public object GetPager(GridPageModel pager, AccountModel.Search search, bool studented = false)
        {
            using (var dbScope = _dbScopeFactory.CreateReadOnly())
            {
                var db        = dbScope.DbContexts.Get <WebDbContext>();
                var tempQuery = from p in db.SysAccounts
                                join aa in db.SysAccountRoles on p.Id equals aa.UserId into tempA
                                from a in tempA.DefaultIfEmpty()
                                join bb in db.SysRoles on a.RoleId equals bb.Id into tempB
                                from b in tempB.DefaultIfEmpty()
                                where (string.IsNullOrEmpty(search.SearchKey) ? true : (p.RealName.Contains(search.SearchKey) || p.UserName.Contains(search.SearchKey))) &&
                                (search.usertype.HasValue ? p.UserType == search.usertype.Value : true) &&
                                (studented ? p.UserType == (int)SysEnum.UserType.学生 : true)
                                select new AccountModel.Full
                {
                    CreateDate = p.CreateDate,
                    HeadPoint  = p.HeadPoint,
                    Id         = p.Id,
                    IsEnabled  = p.IsEnabled,
                    Password   = p.Password,
                    RealName   = p.RealName,
                    RoleName   = b.RoleName,
                    UserName   = p.UserName,
                    UserType   = p.UserType
                };
                var tempTable = tempQuery.ToList();
                var query     = from p in tempTable
                                group p by new { p.CreateDate, p.HeadPoint, p.Id, p.IsEnabled, p.Password, p.RealName, p.UserName, p.UserType } into g
                select g.Aggregate((now, next) => new AccountModel.Full
                {
                    CreateDate = g.Key.CreateDate,
                    HeadPoint  = g.Key.HeadPoint,
                    Id         = g.Key.Id,
                    IsEnabled  = g.Key.IsEnabled,
                    Password   = g.Key.Password,
                    RealName   = g.Key.RealName,
                    RoleName   = now.RoleName + "," + next.RoleName,
                    UserName   = g.Key.UserName,
                    UserType   = g.Key.UserType
                });

                return(new PagedList <AccountModel.Full>(query.ToList(), pager).ToPager());
            }
        }