/// <summary>
        /// 加载一个部门及子部门全部用户
        /// </summary>
        public dynamic Load(int orgId, int pageindex, int pagesize)
        {
            if (pageindex < 1)
            {
                pageindex = 1;                 //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
            }
            IEnumerable <User> users;
            int total = 0;

            if (orgId == 0)
            {
                users = _repository.LoadUsers(pageindex, pagesize);
                total = _repository.GetCount();
            }
            else
            {
                users = _repository.LoadInOrgs(pageindex, pagesize, GetSubOrgIds(orgId));
                total = _repository.GetUserCntInOrgs(orgId);
            }
            var userviews = new List <UserView>();

            foreach (var user in users)
            {
                UserView uv = user;
                uv.Organizations = string.Join(",", _orgRepository.LoadByUser(user.Id).Select(u => u.Name).ToList());
                userviews.Add(uv);
            }

            return(new
            {
                total = total,
                list = userviews,
                pageCurrent = pageindex
            });
        }
Пример #2
0
        /// <summary>
        /// 加载一个部门及子部门全部用户
        /// </summary>
        public GridData Load(Guid orgId, int pageindex, int pagesize)
        {
            if (pageindex < 1)
            {
                pageindex = 1;                 //TODO:如果列表为空新增加一个用户后,前端会传一个0过来,奇怪??
            }
            IEnumerable <User> users;
            int records = 0;

            if (orgId == Guid.Empty)
            {
                users   = _repository.LoadUsers(pageindex, pagesize);
                records = _repository.GetCount();
            }
            else
            {
                var ids = GetSubOrgIds(orgId);
                users   = _repository.LoadInOrgs(pageindex, pagesize, ids);
                records = _repository.GetUserCntInOrgs(ids);
            }
            var userviews = new List <UserView>();

            foreach (var user in users)
            {
                UserView uv   = user;
                var      orgs = _orgRepository.LoadByUser(user.Id);
                uv.Organizations   = string.Join(",", orgs.Select(u => u.Name).ToList());
                uv.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
                userviews.Add(uv);
            }

            return(new GridData
            {
                records = records,
                total = (int)Math.Ceiling((double)records / pagesize),
                rows = userviews,
                page = pageindex
            });
        }