예제 #1
0
파일: CrmTest1.cs 프로젝트: ssjylsg/crm
        /// <summary>
        /// 增加系统管理员角色
        /// </summary>
        public void AddRoleAdmin()
        {
            string roleName = "系统管理员";
            var role = DependencyResolver.Resolver<IRoleService>().FindByRoleName(roleName);

            if (role == null)
            {
                role = new Role() { RoleName = roleName, Remark = "CRM 系统管理员" };
                DependencyResolver.Resolver<IRoleService>().Save(role);
            }
            // 删除 CRM 系统管理员 原来的插件
            ExecuteNonQuery(new string[]{@"DELETE FROM Sys_RolePlug WHERE ROLEID IN (
            SELECT ID FROM SYS_ROLE WHERE  ROLENAME ='系统管理员' AND SYSTEMNAME = 'CRM'
            )"});
            // 给角色分配操作功能
            var pageQuery = new PageQuery<IDictionary<string, object>, Plug>(null);
            pageQuery.Condition = new Dictionary<string, object>();
            DependencyResolver.Resolver<IPlugService>().Query(pageQuery);

            foreach (Plug plug in pageQuery.Result.Where(m => m.Parent != null))
            {
                RolePlug rolePlug = new RolePlug();
                rolePlug.Role = role;
                rolePlug.Plug = plug;
                DependencyResolver.Resolver<IRolePlugService>().Save(rolePlug);
            }
        }
예제 #2
0
        protected void tvMenu_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            var plug = this.PlugService.FindById(int.Parse(e.Node.Value));
            var model = this.CurrentRole;
            RolePlug opr = this.RolePlugService.FindRolePlugById(model.Id, plug.Id);
            if (opr != null)
            {
                opr.Deleted = !e.Node.Checked;
                opr.ModifyTime = DateTime.Now;
                this.RolePlugService.Update(opr);
            }
            else if (e.Node.Checked)
            {
                opr = new RolePlug();
                opr.Optor = this.CurrentOperatorUser;
                opr.Role = model;
                opr.Plug = plug;

                this.RolePlugService.Save(opr);
            }
        }