public UserLiteDto GetUser(string loginName, string password) { var pwdMD5 = CommonFunction.GetMD5String(password); var engine = PermissionDb.CreateEngine(); var dbUser = engine.Esmart_Sys_Users.FirstOrDefault( a => (a.Mobile == loginName || a.Email == loginName) && a.PassWord == pwdMD5); if (dbUser == null) { throw new TpoBaseException("用户登录失败,请重新登录"); } if (dbUser.Isleave == 1) { throw new TpoBaseException("用户已经离职,不能再登录系统"); } return(new UserLiteDto { UserID = dbUser.UserID, Email = dbUser.Email, TrueName = dbUser.TrueName, Ename = dbUser.Ename, Sex = dbUser.Sex, WorkNo = dbUser.WorkNo }); }
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()); }
public List <UserLiteDto> GetUsersByFunctionKey(string functionKey, int userId) { var engine = PermissionDb.CreateEngine(); var funcId = engine.Esmart_Sys_Functions.Where(n => n.FunctionKey == functionKey).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 where user.Isleave != 1 && user.IsDelete != 1 && roleFunc.FunctionId == funcId 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 where user.Isleave != 1 && user.IsDelete != 1 && userFunc.FunctionId == funcId select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }); List <UserLiteDto> lstUsers = query1.ToList(); var allUsers = lstUsers.Where((x, i) => lstUsers.FindIndex(f => f.UserID == x.UserID) == i).ToList(); if (userId > 0) { //----------------------- // 获取用户所属部门所有用户 //----------------------- var dbDepartments = DepartmentDbAction.GetDepartments(userId); var departmentIds = new List <int>(100); GetUserDepartmentIds(dbDepartments, departmentIds); var query2 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId where departmentIds.Contains(depUser.DeparentId) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo, Sex = user.Sex }; var depUsers = query2.ToArray(); return(allUsers.Intersect(depUsers).ToList()); } return(allUsers); }
//获取组中的学习顾问 private static List <UserLiteDto> GetGroupConsultant(int userId, bool isGettingStudyConsultant) { //----------------------- // 获取所有顾问 //----------------------- var allConsultant = GetConsultant(-1, isGettingStudyConsultant); //----------------------- // 获取用户所属部门所有用户 //----------------------- var engine = PermissionDb.CreateEngine(); var dbDepartments = DepartmentDbAction.GetDepartments(userId); var departmentIds = new List <int>(100); GetUserDepartmentIds(dbDepartments, departmentIds); var query3 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId where departmentIds.Contains(depUser.DeparentId) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo, Sex = user.Sex }; //----------------------- // 取所有顾问和当前部门所有用户的交集并返回 //----------------------- var depUsers = query3.ToArray(); return(allConsultant.Intersect(depUsers).ToList()); }
public static List <Esmart_Sys_Navigation_Function> GetListByNavigationId(int navigationId) { var engine = PermissionDb.CreateEngine(); var list = engine.Esmart_Sys_Navigation_Function.Where(a => a.NavigationId == navigationId).ToList(); CommonAction.ClearCache(); return(list); }
public List <UserLiteDto> GetStudyConsultantLeader(int userId) { var engine = PermissionDb.CreateEngine(); var depId = engine.Esmart_Sys_Department_User.Where(n => n.UserId == userId).Select(n => n.DeparentId).FirstOrDefault(); //所给用户不属于任何部门 if (depId < 1) { return(new List <UserLiteDto>(0)); } var query = from userRole in engine.Esmart_Sys_User_Roles join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId where userRole.UserId == userId && role.RoleName == BuiltinRoles.StudyConsultantAdmin select userRole.UserId; //所给用户不是学习顾问 if (!query.Any()) { return(new List <UserLiteDto>(0)); } //获取所有的上级部门 var parentDepartmentIds = DepartmentDbAction.GetParentDepartments(userId).Select(n => n.DeparentId).ToList(); var query2 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId 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.IsDelete != 1 && user.Isleave != 1 //本组学习顾问组长或值班组长、上级部门的学习顾问主管、学习顾问经理 && ((depUser.DeparentId == depId && (role.RoleName == BuiltinRoles.StudyConsultantAdmin || role.RoleName == BuiltinRoles.StudyConsultantAdmin)) || (parentDepartmentIds.Contains(depId) && role.RoleName == BuiltinRoles.StudyConsultantAdmin) || role.RoleName == BuiltinRoles.StudyConsultantAdmin) select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }; return(query2.Distinct().ToList()); }
//获取当前用户信息 private static List <UserLiteDto> GetCurrentUser(int userId) { var engine = PermissionDb.CreateEngine(); var userlite = engine.Esmart_Sys_Users.Where(n => n.UserID == userId).Select(user => new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo, Sex = user.Sex }).FirstOrDefault(); return(userlite == null ? new List <UserLiteDto>(0) : new List <UserLiteDto>() { userlite }); }
public List <UserLiteDto> GetUsersByRoleName(string roleName) { 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 role.RoleName == roleName && user.Isleave != 1 && user.IsDelete != 1 select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }; return(query.ToList()); }
private static void CreateBuiltinRole() { var builtinRoles = new HashSet <string>(BuiltinRoles.All); var dbContext = PermissionDb.CreateEngine(); var dbTable = dbContext.Esmart_Sys_Roles; var maxRoleId = dbTable.Max(n => n.RoleId); foreach (var dbRole in dbTable.ToArray()) { if (builtinRoles.Contains(dbRole.RoleName)) { dbRole.IsBuiltin = true; dbRole.EndTime = new DateTime(9999, 1, 1); if (dbRole.StartTime > DateTime.Today) { dbRole.StartTime = DateTime.Now.AddYears(-1); } builtinRoles.Remove(dbRole.RoleName); } else { dbRole.IsBuiltin = false; } } foreach (var bRole in builtinRoles) { dbTable.Add(new Esmart_Sys_Roles { RoleId = ++maxRoleId, RoleName = bRole, StartTime = DateTime.Now.AddYears(-1), EndTime = new DateTime(9999, 1, 1), CreateId = 1, CreateTime = DateTime.Now, IsBuiltin = true }); } dbContext.SaveChanges(); }
public List <UserLiteDto> GetScheduleConsultantLeader(int userId) { var engine = PermissionDb.CreateEngine(); var depId = engine.Esmart_Sys_Department_User.Where(n => n.UserId == userId).Select(n => n.DeparentId).FirstOrDefault(); //所给用户不属于任何部门 if (depId < 1) { return(new List <UserLiteDto>(0)); } var query = from userRole in engine.Esmart_Sys_User_Roles join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId where userRole.UserId == userId && role.RoleName == BuiltinRoles.StudyConsultantAdmin select userRole.UserId; //所给用户不是排课顾问 if (!query.Any()) { return(new List <UserLiteDto>(0)); } //返回学习顾问组长列表 var query2 = from user in engine.Esmart_Sys_Users join depUser in engine.Esmart_Sys_Department_User on user.UserID equals depUser.UserId 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.IsDelete != 1 && user.Isleave != 1 && depUser.DeparentId == depId && role.RoleName == BuiltinRoles.StudyConsultantAdmin select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }; return(query2.ToList()); }
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); }
//获取所有的学习顾问或排课顾问 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); }
public static bool Update(List <Esmart_Sys_Navigation_Function> listModel, int navigationId) { var engine = PermissionDb.CreateEngine(); //删除 var navigationFunction = engine.Esmart_Sys_Navigation_Function.Where(m => m.NavigationId == navigationId); if (navigationFunction.Any()) { engine.Esmart_Sys_Navigation_Function.RemoveRange(navigationFunction); } if (listModel != null && listModel.Any()) { engine.Esmart_Sys_Navigation_Function.AddRange(listModel); } int reInt = engine.SaveChanges(); int createId = listModel.First().CreateId; RightLogDb.AddLog(new Esmart_Right_Log { CreateBy = createId, CreateTime = System.DateTime.Now, EventType = "update", OprTbName = "Esmart_Sys_Navigation_Function", OprUserId = createId, OptDescription = string.Format("用户:{0}修改了菜单功能关系,其中删除关系表ID:{1},添加关系表ID:{2}", createId, string.Join(",", navigationFunction.Select(s => s.NavigationId)), string.Join(",", listModel)), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(navigationFunction) + ";" + Newtonsoft.Json.JsonConvert.SerializeObject(listModel) }); CommonAction.ClearCache(); return(reInt > 0); }
public List <UserLiteDto> GetAllUsersByFunctionKey(string functionKey, int appId, int menuId = 0) { var engine = PermissionDb.CreateEngine(); var funcId = engine.Esmart_Sys_Functions.Where(n => n.FunctionKey == functionKey && n.AppId == appId).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 where user.Isleave != 1 && user.IsDelete != 1 && roleFunc.FunctionId == funcId && (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 where user.Isleave != 1 && user.IsDelete != 1 && userFunc.FunctionId == funcId select new UserLiteDto { UserID = user.UserID, Ename = user.Ename, TrueName = user.TrueName, WorkNo = user.WorkNo }); List <UserLiteDto> lstUsers = query1.ToList(); var allUsers = lstUsers.Where((x, i) => lstUsers.FindIndex(f => f.UserID == x.UserID) == i).ToList(); return(allUsers); }