예제 #1
0
        public List <AppShortInfo> GetAppListByUserId(int userId)
        {
            if (CommonAction.IsSysAdmin(userId))
            {
                return(AppManagerDb.GetAppList().ConvertAll(a => new AppShortInfo()
                {
                    AppId = a.AppID, AppName = a.AppName, Domain = a.Domain
                }));
            }

            var engine = PermissionDb.CreateEngine();

            //engine.Database.Log = log => System.Diagnostics.Debug.WriteLine(log);

            var roleIds    = engine.Esmart_Sys_User_Roles.Where(n => n.UserId == userId).Select(n => n.RoleId).ToArray();
            var userAppIds = ((from nav in engine.Esmart_Sys_Navigations
                               join roleNav in engine.Esmart_Sys_Role_Navigations on nav.NavigationId equals roleNav.NavigationId
                               where roleIds.Contains(roleNav.RoleId)
                               group nav by nav.AppId into appid
                               select appid.Key).Union
                                  (from nav in engine.Esmart_Sys_Navigations
                                  join userNav in engine.Esmart_Sys_User_Navigations on nav.NavigationId equals userNav.NavigationId
                                  where userNav.UserId == userId
                                  group nav by nav.AppId into appid
                                  select appid.Key)).ToList();
            var apps = AppManagerDb.GetAppList().Where(n => userAppIds.Contains(n.AppID));

            return(apps.Select(n => new AppShortInfo()
            {
                AppId = n.AppID, AppName = n.AppName, Domain = n.Domain
            }).ToList());
        }
예제 #2
0
        public List <UserLiteDto> GetGroupUsersByLoginUserID(int userId)
        {
            List <UserLiteDto> lstResult = null;

            try
            {
                SoaDataPage <UserSearchModel> filter = new SoaDataPage <UserSearchModel>();;
                CommonFunction.InitializeSoaDataPage(filter);
                filter.Where.UserId = userId;
                filter.PageIndex    = 1;
                filter.PageSize     = 100000000;
                var result = new Esmart.Permission.Application.DeparentManager.DepartmentManager().GetUsersByDepartList(filter);
                if (result != null && !CommonAction.IsSysAdmin(userId))
                {
                    List <UsersView> lstDepart = DepartmentUserDbAction.GetGroupsByUserId(userId);
                    lstResult = result.Body.Where(w => lstDepart.Find(f => f.UserID == w.UserID) != null).ToList().ConvertAll(c => new UserLiteDto {
                        UserID = c.UserID, TrueName = c.TrueName, WorkNo = c.WorkNo, Email = c.Email, Ename = c.Ename, Sex = c.Sex
                    });
                }
                else
                {
                    lstResult = result.Body.ToList().ConvertAll(c => new UserLiteDto {
                        UserID = c.UserID, TrueName = c.TrueName, WorkNo = c.WorkNo, Email = c.Email, Ename = c.Ename, Sex = c.Sex
                    });
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(lstResult);
        }
예제 #3
0
        public bool UpdateUser2(Esmart_Sys_Users user)
        {
            UserManagerDb.Update2(user);

            CommonAction.ClearCache(user.UserID);

            return(true);
        }
예제 #4
0
        public bool UpdateUser(UpdateUserDto user)
        {
            UserManagerDb.Update(user);

            CommonAction.ClearCache(user.UserID);

            return(true);
        }
예제 #5
0
        public List <FunctionModel> GetFunctionByUserIdAndMenuId(int userId, int menuId)
        {
            string cachekey = userId + "-" + menuId;

            var list = CacheManager.CreateCache().Get <List <FunctionModel> >(cachekey);

            if (list != null && list.Count > 0)
            {
                return(list);
            }

            list = new List <FunctionModel>(20);

            if (CommonAction.IsSysAdmin(userId))//如果是管理员 获取菜单所有的功能
            {
                var builtin = BuiltinRoles.All.Select(n => new FunctionModel {
                    FunctionKey = n, FunctionName = n
                });
                list.Add(new FunctionModel {
                    FunctionKey = "$ADMIN", FunctionName = "$ADMIN"
                });
                list.AddRange(builtin);
                list.AddRange(RoleNavigationFunctionDbAction.GetFunctionsByNavigationId(menuId));
            }
            else
            {
                var roles = UserRolesDbAction.GetUserRolses(userId);

                roles.ForEach(n =>
                {
                    if (BuiltinRoles.All.Contains(n.RoleName))
                    {
                        list.Add(new FunctionModel {
                            FunctionKey = n.RoleName, FunctionName = n.RoleName
                        });
                    }
                });

                //角色分配的功能
                var roleIds = roles.Select(p => p.RoleId).ToList();
                ICollection <FunctionModel> funcList     = RoleNavigationFunctionDbAction.GetFunctionsByRoleIdsAndNavigationId(roleIds, menuId);
                ICollection <FunctionModel> userFuncList = UserNavigationFunctionDbAction.GetFunctionsByUserIdsAndNavigationId(new List <int> {
                    userId
                }, menuId);

                list.AddRange(funcList);
                list.AddRange(userFuncList.Except(funcList).ToList());
            }

            CacheManager.CreateCache().Add(cachekey, list);

            return(list);
        }
예제 #6
0
        /// <summary>
        ///根据用户ID和APPId获取菜单权限列表
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="appId"></param>
        /// <returns></returns>
        public List <MenuResponse> GetMenuAndFunctionByUserId(int userId, int appId)
        {
            List <RoleResponse> roles;

            var listMenu = GetMenuByUserId(userId, appId, out roles);

            var menusAndFuns = CommonAction.IsSysAdmin(userId)
                ? Data.MenuManager.GetAllMensFunctions()
                : Data.MenuManager.GetAllMensFunctions(roles.Select(n => n.RoleId).ToList());

            foreach (var menu in listMenu)
            {
                SetFunctions(menu, menusAndFuns);
            }
            return(listMenu);
        }
예제 #7
0
        public int CreateUserWithDepartmentId(Esmart_Sys_Users user, int departMentId)
        {
            if (user.UserID == 0)
            {
                user.CreateTime = DateTime.Now;
                UserManagerDb.Add(user);
            }

            Esmart_Sys_Department_User departUser = new Esmart_Sys_Department_User
            {
                DeparentId = departMentId,
                UserId     = user.UserID,
                CreateTime = DateTime.Now,
                CreateId   = user.CreateId
            };

            DepartmentUserDbAction.Add(departUser);

            CommonAction.ClearCache(user.UserID);

            return(user.UserID);
        }
예제 #8
0
        public List <UserLiteDto> GetGroupUsersByFunctionKey(string functionKey, int userId, int menuId, int appId = 0)
        {
            var engine = PermissionDb.CreateEngine();

            // var funcId = engine.Esmart_Sys_Functions.Where(n => n.FunctionKey == functionKey && n.).Select(n => n.FunctionId).FirstOrDefault();

            //if (funcId < 1) return new List<UserLiteDto>(0);

            var query1 = (from user in engine.Esmart_Sys_Users
                          join userRole in engine.Esmart_Sys_User_Roles on user.UserID equals userRole.UserId
                          join roleFunc in engine.Esmart_Sys_Role_Navigation_Function on userRole.RoleId equals roleFunc.RoleId
                          join func in engine.Esmart_Sys_Functions on roleFunc.FunctionId equals func.FunctionId
                          where user.Isleave != 1 && user.IsDelete != 1 && func.FunctionKey == functionKey && (menuId > 0 ? roleFunc.NavigationId == menuId : true)
                          select new UserLiteDto
            {
                UserID = user.UserID,
                Ename = user.Ename,
                TrueName = user.TrueName,
                WorkNo = user.WorkNo
            }).Union(
                from user in engine.Esmart_Sys_Users
                join userFunc in engine.Esmart_Sys_User_Navigation_Function on user.UserID equals userFunc.UserId
                join func in engine.Esmart_Sys_Functions on userFunc.FunctionId equals func.FunctionId
                where user.Isleave != 1 && user.IsDelete != 1 && func.FunctionKey == functionKey && (menuId > 0 ? userFunc.NavigationId == menuId : true)
                select new UserLiteDto
            {
                UserID   = user.UserID,
                Ename    = user.Ename,
                TrueName = user.TrueName,
                WorkNo   = user.WorkNo
            });

            var groupUsers = DepartmentUserDbAction.GetGroupsByUserId(userId);
            var filterto   = groupUsers.ConvertAll(c => c.UserID);
            List <UserLiteDto> lstUsers = CommonAction.IsSysAdmin(userId)?query1.ToList(): query1.Where(w => filterto.Contains(w.UserID)).ToList();
            var allUsers = lstUsers.Where((x, i) => lstUsers.FindIndex(f => f.UserID == x.UserID) == i).ToList();

            return(allUsers);
        }
예제 #9
0
        //获取所有的学习顾问或排课顾问
        private static List <UserLiteDto> GetAllConsultant(IEnumerable <string> roleNames, bool isGettingStudyConsultant)
        {
            var engine = PermissionDb.CreateEngine();

            var query = from user in engine.Esmart_Sys_Users
                        join userRole in engine.Esmart_Sys_User_Roles on user.UserID equals userRole.UserId
                        join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId
                        where user.Isleave != 1 && user.IsDelete == 0
                        //&& !excludeUserIds.Contains(userRole.UserId)
                        && roleNames.Contains(role.RoleName)
                        select new UserLiteDto
            {
                UserID   = user.UserID,
                Ename    = user.Ename,
                TrueName = user.TrueName,
                WorkNo   = user.WorkNo,
                Sex      = user.Sex
            };

            if (!isGettingStudyConsultant)
            {
                //11月24日 添加了排除 教务质监 角色的关联用户
                //12月1日  学习顾问不再排除教务质监
                var query1 = from userRole in engine.Esmart_Sys_User_Roles
                             join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId
                             where role.RoleName == BuiltinRoles.ScheduleConsultantAdmin
                             select userRole.UserId;

                var excludeUserIds = query1.ToArray();

                query = query.Where(n => !excludeUserIds.Contains(n.UserID));
            }

            var list = query.Distinct().ToList();

            //将超级管理员排除
            list.RemoveAll(n => CommonAction.IsSysAdmin(n.UserID));
            return(list);
        }
예제 #10
0
        public List <MenuResponse> GetMenuByUserId(int userId, int appId, out List <RoleResponse> roles)
        {
            roles = UserManagerDb.GetRolesByUserId(userId);

            List <MenuResponse> menus = null;

            if (CommonAction.IsSysAdmin(userId))
            {
                menus = RoleNavigationFunctionDbAction.GetAdminMenu(appId);
            }
            else
            {
                menus = new List <MenuResponse>();
                menus.AddRange(RoleNavigationFunctionDbAction.GetMenuFunctions(roles.Select(n => n.RoleId).ToList(), appId));
                menus.AddRange(UserNavigationFunctionDbAction.GetMenuFunctions(new List <int> {
                    userId
                }, appId));
                menus = menus.Where((i, j) => menus.FindIndex(f => f.Id == i.Id) == j).ToList();
            }
            //var menus = CommonAction.IsSysAdmin(userId)
            //    ? RoleNavigationFunctionDbAction.GetAdminMenu(appId)
            //    : RoleNavigationFunctionDbAction.GetMenuFunctions(roles.Select(n => n.RoleId).ToList(), appId);

            var topMenus = new List <MenuResponse>();

            foreach (var fun in menus)
            {
                GetTopMenu(fun, menus, topMenus);
            }

            foreach (var menu in topMenus)
            {
                SetChildren(menus, menu);
            }

            return(topMenus);
        }
예제 #11
0
        /// <summary>
        /// 获取当前部门以外的用户列表 by wangligui
        /// </summary>
        public List <DepartmentUserResponse> GetUserOutDepartment(int departmentId, int loginUserId)
        {
            var isSysAdmin = CommonAction.IsSysAdmin(loginUserId);

            return(DepartmentUserDbAction.GetUserOutDepartment(departmentId, loginUserId, isSysAdmin));
        }