Exemplo n.º 1
0
        public static int Add(Esmart_Sys_Navigations model)
        {
            var engine = PermissionDb.CreateEngine();
            int max;

            try
            {
                max = engine.Esmart_Sys_Navigations.Max(a => a.NavigationId);
            }
            catch
            {
                max = 0;
            }
            model.NavigationId = max + 1;

            model.CreateTime = DateTime.Now;

            engine.Esmart_Sys_Navigations.Add(model);

            int code = engine.SaveChanges();

            if (code <= 0)
            {
                throw new TpoBaseException("新增异常");
            }
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = System.DateTime.Now, EventType = "add", OprTbName = "Esmart_Sys_Navigations", OprUserId = model.CreateId, OptDescription = string.Format(logFormat, model.CreateId, "添加", model.NavigationId), Remark = JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();

            return(model.NavigationId);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Update(Esmart_Sys_Functions model)
        {
            var engine = PermissionDb.CreateEngine();

            if (engine.Esmart_Sys_Functions.Any(m => m.FunctionId != model.FunctionId && m.FunctionKey == model.FunctionKey && m.AppId == model.AppId))
            {
                throw new TpoBaseException("功能key已存在,请重新输入");
            }

            var functions = engine.Esmart_Sys_Functions.Find(model.FunctionId);

            if (functions != null)
            {
                functions.AppId        = model.AppId;
                functions.CreateId     = model.CreateId;
                functions.FunctionKey  = model.FunctionKey;
                functions.FunctionName = model.FunctionName;
                functions.Remark       = model.Remark;
                engine.SaveChanges();
                RightLogDb.AddLog(new Esmart_Right_Log {
                    CreateBy = model.CreateId, CreateTime = System.DateTime.Now, EventType = "update", OprTbName = "Esmart_Sys_Functions", OprUserId = model.CreateId, OptDescription = string.Format("用户:{0}修改了功能,ID:{1}", model.CreateId, model.FunctionId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(functions)
                });
                return(true);
            }

            CommonAction.ClearCache();
            return(false);
        }
Exemplo n.º 3
0
        public static IEnumerable <Esmart_Sys_Departments> GetParentDepartments(int?userId)
        {
            var result = new List <Esmart_Sys_Departments>(10);

            if (userId.HasValue)
            {
                var resultSet         = new HashSet <int>();
                var engine            = PermissionDb.CreateEngine();
                var userDepartmentIds = engine.Esmart_Sys_Department_User.Where(n => n.UserId == userId).Select(n => n.DeparentId).ToList();
                var departmentDic     = GetDepartmentDic(engine);
                foreach (var depId in userDepartmentIds)
                {
                    var parentId = depId;
                    while (parentId > 0)
                    {
                        Esmart_Sys_Departments department;
                        if (resultSet.Contains(parentId) || !departmentDic.TryGetValue(parentId, out department))
                        {
                            break;
                        }
                        result.Add(department);
                        resultSet.Add(parentId);
                        parentId = department.ParentId;
                    }
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        private static Dictionary <int, Esmart_Sys_Departments> GetDepartmentDic(PermissionContext engine)
        {
            var dic = CacheManager.CreateCache().Get <Dictionary <int, Esmart_Sys_Departments> >(CacheKey.Authorize_DepartmentDic);

            if (dic == null || dic.Count == 0)
            {
                //从线性数组转换为树形
                engine = engine ?? PermissionDb.CreateEngine();
                var linearList = engine.Esmart_Sys_Departments.Where(n => n.IsDelete == 0).OrderBy(n => n.ParentId).ToList();
                dic = new Dictionary <int, Esmart_Sys_Departments>(linearList.Count);
                foreach (var item in linearList)
                {
                    dic[item.DeparentId] = item;
                    Esmart_Sys_Departments department;
                    if (dic.TryGetValue(item.ParentId, out department))
                    {
                        if (department.Children == null)
                        {
                            department.Children = new List <Esmart_Sys_Departments>(20);
                        }
                        department.Children.Add(item);
                    }
                }
                CacheManager.CreateCache().Set(CacheKey.Authorize_DepartmentDic, dic);
            }
            return(dic);
        }
Exemplo n.º 5
0
        private static int AddUser(Esmart_Sys_Users model)
        {
            var engine = PermissionDb.CreateEngine();

            CheckUser(engine, model);

            model.UserID = (engine.Esmart_Sys_Users.Max(m => (int?)m.UserID) ?? 0) + 1;

            var password = "******"; //RandomString.Generate(8);

            // new MailService().SendRegisterInfo(model.Email, model.UserID, password);

            model.PassWord = CommonFunction.GetMD5String(password);
            model.Isleave  = 0;

            engine.Esmart_Sys_Users.Add(model);

            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = System.DateTime.Now, EventType = "add", OprTbName = "Esmart_Sys_Users", OprUserId = model.CreateId, OptDescription = string.Format("用户:{0}添加了用户信息,用户ID:{1}", model.CreateId, model.UserID), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache(model.UserID);

            return(model.UserID);
        }
Exemplo n.º 6
0
        public static List <Esmart_Sys_Navigations> GetListByParentId(int parentId)
        {
            var engine = PermissionDb.CreateEngine();
            var list   = engine.Esmart_Sys_Navigations.Where(m => m.ParentID == parentId);

            return(list.ToList());
        }
Exemplo n.º 7
0
        public static bool ModifyPassword(string userAccount, string password, string newPassword, int optUserId = 0)
        {
            var engine = PermissionDb.CreateEngine();
            var user   = engine.Esmart_Sys_Users.FirstOrDefault(m => m.Isleave != 1 && m.IsDelete != 1 && (m.Email == userAccount || m.Mobile == userAccount));

            if (user == null)
            {
                throw new TpoBaseException("用户帐号不存在");
            }

            if (user.PassWord != CommonFunction.GetMD5String(password))
            {
                throw new TpoBaseException("用户密码错误");
            }

            if (password == newPassword)
            {
                throw new TpoBaseException("新密码不能与旧密码相同!");
            }

            user.PassWord = CommonFunction.GetMD5String(newPassword);
            engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "update", OprTbName = "Esmart_Sys_Users", OprUserId = optUserId, OptDescription = string.Format("用户:{0}修改了用户{1}密码,账号为:{2}", optUserId, user.UserID, userAccount), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(user)
            });
            return(true);
        }
        public static List <MenuResponse> GetMenuFunctions(List <int> roles, int appId)
        {
            if (roles == null || roles.Count == 0)
            {
                return(new List <MenuResponse>(0));
            }

            var engine = PermissionDb.CreateEngine();

            var data = from roleNav in engine.Esmart_Sys_Role_Navigations
                       join menu in engine.Esmart_Sys_Navigations
                       on roleNav.NavigationId equals menu.NavigationId
                       where roles.Contains(roleNav.RoleId) && menu.AppId == appId
                       orderby menu.SortNo descending
                       select new MenuResponse
            {
                Iconurl      = menu.Iconurl,
                InClassName  = menu.InClassName,
                Id           = menu.NavigationId,
                OutClassName = menu.OutClassName,
                ParentId     = menu.ParentID,
                Name         = menu.Title,
                Url          = !string.IsNullOrEmpty(menu.Url) ? (menu.Url.IndexOf("?") == -1 ? menu.Url + "?PageId=" + menu.NavigationId : "&PageId=" + menu.NavigationId) : "#"
            };

            return(data.Distinct().ToList());
        }
Exemplo n.º 9
0
        /// <summary>
        /// 修改角色
        /// </summary>
        /// <returns>true|false</returns>
        public static bool Update(RoleModel dto)
        {
            var engine = PermissionDb.CreateEngine();

            var role = engine.Esmart_Sys_Roles.Find(dto.Id);

            if (role.IsBuiltin)
            {
                throw new TpoBaseException("系统角色不允许修改");
            }

            if (engine.Esmart_Sys_Roles.Any(n => n.RoleId != role.RoleId && n.RoleName == dto.Name))
            {
                throw new TpoBaseException("角色名称已经存在");
            }

            role.RoleName  = dto.Name.Trim();
            role.Remark    = dto.Remark;
            role.StartTime = dto.StartDate ?? DateTime.Now;
            role.EndTime   = dto.EndDate ?? role.StartTime.Value.AddYears(99);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = dto.CreatorId, CreateTime = System.DateTime.Now, EventType = "update", OprTbName = "Esmart_Sys_Roles", OprUserId = dto.CreatorId, OptDescription = string.Format(logFormat, dto.CreatorId, "更新", dto.Id), Remark = JsonConvert.SerializeObject(role)
            });
            CommonAction.ClearCache();
            return(true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(Esmart_Sys_Functions model)
        {
            var engine = PermissionDb.CreateEngine();

            //appid相同key不能重复
            if (engine.Esmart_Sys_Functions.Any(m => m.AppId == model.AppId && m.FunctionKey == model.FunctionKey))
            {
                throw new TpoBaseException("功能key已存在,请重新输入");
            }

            model.FunctionId = 1;
            if (engine.Esmart_Sys_Functions.Any())
            {
                model.FunctionId = engine.Esmart_Sys_Functions.Max(m => m.FunctionId) + 1;
            }

            engine.Esmart_Sys_Functions.Add(model);
            var count = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = System.DateTime.Now, EventType = "add", OprTbName = "Esmart_Sys_Functions", OprUserId = model.CreateId, OptDescription = string.Format("用户:{0}添加了功能,ID:{1}", model.CreateId, model.FunctionId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();
            return(count > 0);
        }
Exemplo n.º 11
0
        public static List <Esmart_Sys_Navigation_Function> GetMenusFunctions(List <int> menuIds)
        {
            var engine = PermissionDb.CreateEngine();
            var list   = engine.Esmart_Sys_Navigation_Function.Where(a => menuIds.Contains(a.NavigationId));

            return(list.ToList());
        }
Exemplo n.º 12
0
        /// <summary>
        /// 获取部门已经分配的角色
        /// </summary>
        public static List <Esmart_Sys_Roles> GetAssignedRolesOfDepartment(int departmentId)
        {
            var engine = PermissionDb.CreateEngine();
            var query  = from role in engine.Esmart_Sys_Roles
                         join dep_role in engine.Esmart_Sys_Deparent_Role on role.RoleId equals dep_role.RoleId
                         where dep_role.DeparentId == departmentId
                         select role;

            return(query.ToList());
        }
Exemplo n.º 13
0
        public static List <Esmart_Sys_Roles> GetUserRolses(int userId)
        {
            var engine = PermissionDb.CreateEngine();
            var query  = from role in engine.Esmart_Sys_Roles
                         join userRole in engine.Esmart_Sys_User_Roles on role.RoleId equals userRole.RoleId
                         where userRole.UserId == userId
                         select role;

            return(query.ToList());
        }
Exemplo n.º 14
0
        public static void Log(int createId, DateTime createTime, string remark)
        {
            var engine = PermissionDb.CreateEngine();
            var model  = new Esmart_Sys_LogInfo()
            {
                CreateID = createId, CreateTime = createTime, Remark = remark
            };

            engine.Esmart_Sys_LogInfo.Add(model);
            engine.SaveChanges();
        }
Exemplo n.º 15
0
        public static void Add(Esmart_Sys_Departments model)
        {
            var engine = PermissionDb.CreateEngine();

            model.DeparentId = (engine.Esmart_Sys_Departments.Max(n => (int?)n.DeparentId) ?? 0) + 1;
            engine.Esmart_Sys_Departments.Add(model);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = DateTime.Now, EventType = "add", OprTbName = "Esmart_Sys_Departments", OprUserId = model.CreateId, OptDescription = string.Format(logFormat, model.CreateId, System.DateTime.Now, "添加", model.DeparentId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();
        }
Exemplo n.º 16
0
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static bool Add(Esmart_Sys_Department_User model)
        {
            var engine = PermissionDb.CreateEngine();

            engine.Esmart_Sys_Department_User.Add(model);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = model.CreateTime, EventType = "add", OprTbName = "Esmart_Sys_Department_User", OprUserId = model.CreateId, OptDescription = string.Format("用户:{0}添加了部门关系用户,用户ID:{1},部门ID:{2}", model.CreateId, model.UserId, model.DeparentId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();
            return(true);
        }
Exemplo n.º 17
0
        /// <summary>
        /// 给角色添加菜单和功能
        /// </summary>
        /// <returns></returns>
        public static bool AssignPermissionRole(int roleId, int appId, List <Esmart_Sys_Role_Navigations> roleNavigationses, List <Esmart_Sys_Role_Navigation_Function> roleNavigationFunctions)
        {
            var engine = PermissionDb.CreateEngine();

            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            //获取要删除的Esmart_Sys_Role_Navigations集合
            var navigations = (from a in engine.Esmart_Sys_Role_Navigations.ToList()
                               join b in engine.Esmart_Sys_Navigations.ToList()
                               on a.NavigationId equals b.NavigationId
                               where a.RoleId == roleId && b.AppId == appId
                               select a).ToList();

            //获取要删除的Esmart_Sys_Role_Navigation_Function集合
            var functions = (from a in engine.Esmart_Sys_Role_Navigation_Function.ToList()
                             join b in engine.Esmart_Sys_Functions.Where(a => a.AppId == appId).ToList()
                             on a.FunctionId equals b.FunctionId
                             where a.RoleId == roleId
                             select a).ToList();

            //删除Esmart_Sys_Role_Navigations
            engine.Esmart_Sys_Role_Navigations.RemoveRange(navigations);

            //删除Esmart_Sys_Role_Navigation_Function
            engine.Esmart_Sys_Role_Navigation_Function.RemoveRange(functions);

            if (roleNavigationses.Count > 0)
            {
                //批量添加Esmart_Sys_Role_Navigations
                engine.Esmart_Sys_Role_Navigations.AddRange(roleNavigationses);

                //批量添加Esmart_Sys_Role_Navigation_Function
                engine.Esmart_Sys_Role_Navigation_Function.AddRange(roleNavigationFunctions);
            }
            else if (roleNavigationFunctions.Count > 0)
            {
                //批量添加Esmart_Sys_Role_Navigation_Function
                engine.Esmart_Sys_Role_Navigation_Function.AddRange(roleNavigationFunctions);
            }

            //一起提交到数据库  事务
            engine.SaveChanges();
            int createId = roleNavigationses.First().CreateId;

            sb.Append(JsonConvert.SerializeObject(navigations)).Append(";").Append(JsonConvert.SerializeObject(functions)).Append(";").Append(JsonConvert.SerializeObject(roleNavigationses)).Append(";").Append(JsonConvert.SerializeObject(roleNavigationFunctions));
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = createId, CreateTime = System.DateTime.Now, EventType = "add&delete", OprTbName = "Esmart_Sys_Role_Navigations,Esmart_Sys_Role_Navigation_Function", OprUserId = createId, OptDescription = string.Format("用户:{0}修改了角色菜单关系,其中删除角色菜单关系表ID:{1},删除角色菜单功能关系表ID:{2},添加角色菜单关系表ID:{3},添加角色菜单功能关系表ID:{4}", createId, string.Join(",", navigations.Select(s => s.Id)), string.Join(",", functions.Select(s => s.Id)), string.Join(",", roleNavigationses.Select(s => s.Id)), roleNavigationFunctions.Select(s => s.Id)), Remark = sb.ToString()
            });
            CommonAction.ClearCache();
            sb.Length = 0;
            return(true);
        }
Exemplo n.º 18
0
        public static int AssignDepartmentRoles(int departmentId, int creatId, List <int> roleIds)
        {
            var engine = PermissionDb.CreateEngine();

            System.Text.StringBuilder sb = new System.Text.StringBuilder(), sbDesc = new System.Text.StringBuilder();
            //-----------------------------------------
            // 保存部门角色
            //-----------------------------------------
            var entities = engine.Esmart_Sys_Deparent_Role.Where(a => a.DeparentId == departmentId).ToList();

            engine.Esmart_Sys_Deparent_Role.RemoveRange(entities);
            sb.Append("删除部门角色:").Append(JsonConvert.SerializeObject(entities)).Append(";");
            foreach (var item in roleIds)
            {
                engine.Esmart_Sys_Deparent_Role.Add(new Esmart_Sys_Deparent_Role()
                {
                    CreateId = creatId, CreateTime = DateTime.Now, RoleId = item, DeparentId = departmentId
                });
            }
            sb.Append("添加部门角色:").Append(JsonConvert.SerializeObject(engine.Esmart_Sys_Deparent_Role.ToList())).Append(";");
            //-----------------------------------------
            // 注入部门角色到用户角色列表中
            //-----------------------------------------
            var query = from user in engine.Esmart_Sys_Users
                        join dep_user in engine.Esmart_Sys_Department_User on user.UserID equals dep_user.UserId
                        where dep_user.DeparentId == departmentId
                        select user.UserID;

            foreach (var userId in query.ToArray())
            {
                var userRoleIds   = engine.Esmart_Sys_User_Roles.Where(n => n.UserId == userId).Select(n => n.RoleId).ToArray();
                var exceptRoleIds = roleIds.Except(userRoleIds);
                foreach (var roleId in exceptRoleIds)
                {
                    engine.Esmart_Sys_User_Roles.Add(new Esmart_Sys_User_Roles()
                    {
                        CreateId = creatId, CreateTime = DateTime.Now, RoleId = roleId, UserId = userId
                    });
                }
            }
            sb.Append("删除用户角色:").Append(JsonConvert.SerializeObject(engine.Esmart_Sys_User_Roles.ToList()));
            //-----------------------------------------
            // 保存并清空缓存
            //-----------------------------------------
            var result = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = creatId, CreateTime = System.DateTime.Now, EventType = "add&delete", OprTbName = "Esmart_Sys_Deparent_Role,Esmart_Sys_User_Roles", OprUserId = creatId, OptDescription = string.Format("用户:{0}修改了部门角色、用户角色关系", creatId), Remark = sb.ToString()
            });
            CommonAction.ClearCache();
            return(result);
        }
Exemplo n.º 19
0
        public static bool DelDepartmentRelation(int userId, int departMentId, int currUser = 0)
        {
            var engine      = PermissionDb.CreateEngine();
            var departUsers = engine.Esmart_Sys_Department_User.Where(a => a.UserId == userId && a.DeparentId == departMentId).ToList();

            engine.Esmart_Sys_Department_User.RemoveRange(departUsers);
            bool isDelSuccess = engine.SaveChanges() > 0;

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = currUser, CreateTime = DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_Department_User", OprUserId = currUser, OptDescription = string.Format("用户:{0}删除了部门关系用户,用户ID:{1},部门ID:{2}", currUser, userId, departMentId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(departUsers)
            });
            return(isDelSuccess);
        }
Exemplo n.º 20
0
        public static int RemoveUserRole(int userId, int roleId, int optUserId = 0)
        {
            var engine = PermissionDb.CreateEngine();
            var items  = engine.Esmart_Sys_User_Roles.Where(n => n.UserId == userId && n.RoleId == roleId).ToArray();

            engine.Esmart_Sys_User_Roles.RemoveRange(items);
            int updateCount = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_User_Roles", OprUserId = optUserId, OptDescription = string.Format("用户:{0}删除了用户角色关系,用户ID:{1},角色ID{2}", optUserId, userId, roleId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(items)
            });
            return(updateCount);
        }
Exemplo n.º 21
0
        /// <summary>
        /// 删除当前角色Id对应的数据
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public static bool Del(int userId, int optUserId)
        {
            var engine  = PermissionDb.CreateEngine();
            var entitys = engine.Esmart_Sys_User_Navigations.Where(a => a.UserId == userId).ToList();

            engine.Esmart_Sys_User_Navigations.RemoveRange(entitys);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_User_Navigations", OprUserId = optUserId, OptDescription = string.Format("用户:{0}删除了用户菜单关系,用户ID:{1}", optUserId, userId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(entitys)
            });
            CommonAction.ClearCache();
            return(true);
        }
Exemplo n.º 22
0
        public static bool DeleteUserRoles(int userId, int optUserId = 0)
        {
            var engine   = PermissionDb.CreateEngine();
            var entities = engine.Esmart_Sys_User_Roles.Where(m => m.UserId == userId).ToList();

            engine.Esmart_Sys_User_Roles.RemoveRange(entities);
            var result = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_User_Roles", OprUserId = optUserId, OptDescription = string.Format("用户:{0}删除了用户ID对应的角色关系,用户ID:{1}", optUserId, userId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(entities)
            });
            return(result > 0);
        }
        /// <summary>
        /// 删除当前角色Id对应的数据
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns></returns>
        public static bool Del(int roleId, int optUserId = 0)
        {
            var engine   = PermissionDb.CreateEngine();
            var entities = engine.Esmart_Sys_Role_Navigation_Function.Where(a => a.RoleId == roleId).ToList();

            engine.Esmart_Sys_Role_Navigation_Function.RemoveRange(entities);
            var result = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_Role_Navigation_Function", OprUserId = optUserId, OptDescription = string.Format("用户:{0}{1}了角色菜单功能关系,角色ID:{2}", optUserId, "删除", roleId), Remark = JsonConvert.SerializeObject(entities)
            });
            return(result > 0);
        }
Exemplo n.º 24
0
        public static List <RoleResponse> GetRolesByUserId(int userId)
        {
            var engine = PermissionDb.CreateEngine();

            var roles = from userRole in engine.Esmart_Sys_User_Roles
                        join role in engine.Esmart_Sys_Roles on userRole.RoleId equals role.RoleId
                        where role.StartTime <= DateTime.Now && role.EndTime >= DateTime.Now && userRole.UserId == userId
                        select new RoleResponse
            {
                RoleId   = userRole.RoleId,
                RoleName = role.RoleName
            };

            return(roles.ToList());
        }
Exemplo n.º 25
0
        public static int Delete(Esmart_Sys_Navigations model)
        {
            var engine = PermissionDb.CreateEngine();

            engine.Esmart_Sys_Navigations.Remove(model);

            int reInt = engine.SaveChanges();

            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_Navigations", OprUserId = model.CreateId, OptDescription = string.Format(logFormat, model.CreateId, "删除", model.NavigationId), Remark = JsonConvert.SerializeObject(model)
            });
            CommonAction.ClearCache();

            return(reInt);
        }
Exemplo n.º 26
0
        public static int Update(Esmart_Sys_Departments model)
        {
            var engine = PermissionDb.CreateEngine();

            DbEntityEntry <Esmart_Sys_Departments> entry = engine.Entry(model);

            entry.State = EntityState.Modified;
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = model.CreateId, CreateTime = DateTime.Now, EventType = "update", OprTbName = "Esmart_Sys_Departments", OprUserId = model.CreateId, OptDescription = string.Format(logFormat, model.CreateId, System.DateTime.Now, "修改", model.DeparentId), Remark = Newtonsoft.Json.JsonConvert.SerializeObject(model)
            });
            int result = engine.SaveChanges();

            CommonAction.ClearCache();
            return(result);
        }
Exemplo n.º 27
0
 public static void AddLog(Esmart_Right_Log log)
 {
     try
     {
         if (log != null)
         {
             var engine = PermissionDb.CreateEngine();
             engine.Esmart_Right_Log.Add(log);
             engine.SaveChanges();
         }
     }catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 28
0
        public static List <UsersView> GetGroupsByUserId(int userId)
        {
            var engine = PermissionDb.CreateEngine();

            var groupUsers = from d in engine.Esmart_Sys_Departments join du in engine.Esmart_Sys_Department_User on d.DeparentId equals du.DeparentId
                             join u in engine.Esmart_Sys_Users on du.UserId equals u.UserID
                             where d.IsDelete == 0 && u.IsDelete == 0 && u.Isleave == 0 &&
                             engine.Esmart_Sys_Department_User.Any(a => a.DeparentId == du.DeparentId && a.UserId == userId) &&
                             !engine.Esmart_Sys_Departments.Any(a => d.DeparentId == a.ParentId)
                             select new UsersView {
                UserID = u.UserID, WorkNo = u.WorkNo, TrueName = u.TrueName, Sex = u.Sex, Email = u.Email, Ename = u.Ename, DeparentId = d.DeparentId, DeparentName = d.Name
            };
            List <UsersView> lstResult = groupUsers.ToList();

            return(lstResult.Where((x, i) => lstResult.FindIndex(f => f.UserID == x.UserID) == i).ToList());
        }
Exemplo n.º 29
0
        /// <summary>
        /// 删除角色Id对应的数据
        /// </summary>
        public static bool DeleteByRoleId(int roleId)
        {
            var engine   = PermissionDb.CreateEngine();
            var entities = engine.Esmart_Sys_Deparent_Role.Where(a => a.RoleId == roleId).ToList();

            engine.Esmart_Sys_Deparent_Role.RemoveRange(entities);
            engine.SaveChanges();
            LogHelper <RoleModel> .LogInstance(guid, new Action <UserLiteDto, RoleModel>((users, depart) =>
            {
                RightLogDb.AddLog(new Esmart_Right_Log {
                    CreateBy = users.UserID, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_Deparent_Role", OprUserId = users.UserID, Remark = Newtonsoft.Json.JsonConvert.SerializeObject(entities), OptDescription = string.Format("用户:{0}{1}了部门角色,ID:{2}", users.UserID, "删除", roleId)
                });
            }));

            CommonAction.ClearCache();
            return(true);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns>true|false</returns>
        public static bool Delete(int roleId, int optUserId = 0)
        {
            var engine   = PermissionDb.CreateEngine();
            var entities = engine.Esmart_Sys_Roles.Where(a => a.RoleId == roleId).ToList();

            if (entities.Any(n => n.IsBuiltin))
            {
                throw new TpoBaseException("系统角色不允许删除");
            }
            engine.Esmart_Sys_Roles.RemoveRange(entities);
            engine.SaveChanges();
            RightLogDb.AddLog(new Esmart_Right_Log {
                CreateBy = optUserId, CreateTime = System.DateTime.Now, EventType = "delete", OprTbName = "Esmart_Sys_Roles", OprUserId = optUserId, OptDescription = string.Format(logFormat, optUserId, "删除", roleId), Remark = JsonConvert.SerializeObject(entities)
            });
            CommonAction.ClearCache();
            return(true);
        }