Exemple #1
0
        /// <summary>
        /// 加载当前登录用户可访问的一个部门及子部门全部角色
        /// </summary>
        public TableData Load(QueryCommonReq request)
        {
            var loginUser = AuthUtil.GetCurrentUser();

            string cascadeId = ".0.";

            if (!string.IsNullOrEmpty(request.orgId))
            {
                var org = loginUser.Orgs.SingleOrDefault(u => u.Id == request.orgId);
                cascadeId = org.CascadeId;
            }

            var ids     = loginUser.Orgs.Where(u => u.CascadeId.Contains(cascadeId)).Select(u => u.Id).ToArray();
            var roleIds = ReleManagerApp.Get(Define.ROLEORG, false, ids);

            Expression <Func <Role, bool> > where1 = u => roleIds.Contains(u.Id);

            if (!string.IsNullOrEmpty(request.key))
            {
                where1 = (u => u.Name.Contains(request.key) && roleIds.Contains(u.Id));
            }
            if (request.Status >= 0)
            {
                where1 = (u => (string.IsNullOrEmpty(request.key) ? 1 == 1 : u.Name.Contains(request.key)) && roleIds.Contains(u.Id) && u.Status == request.Status);
            }
            var roles = UnitWork.Find <Role>(where1)
                        .OrderBy(u => u.Name)
                        .Skip((request.page - 1) * request.limit)
                        .Take(request.limit);
            var records = Repository.GetCount(where1);


            var roleViews = new List <RoleView>();

            foreach (var role in roles.ToList())
            {
                RoleView uv   = role;
                var      orgs = LoadByRole(role.Id);
                uv.Organizations   = string.Join(",", orgs.Select(u => u.Name).ToList());
                uv.OrganizationIds = string.Join(",", orgs.Select(u => u.Id).ToList());
                roleViews.Add(uv);
            }

            return(new TableData
            {
                count = records,
                data = roleViews,
            });
        }
Exemple #2
0
 /// <summary>
 /// 加载组织下面的所有角色
 /// </summary>
 public string Load([FromUri] QueryCommonReq request)
 {
     return(JsonHelper.Instance.Serialize(App.Load(request)));
 }