private void btnEnter_Click(object sender, EventArgs e)
        {
            //获取角色权限列表,循坏更改信息
            int count = lbSelModuleList.Items.Count;

            getAllAuthList = sral.GetAllAuthList(roleId);
            int countAuthList       = getAllAuthList.Count;
            SystemRoleAuthority sra = new SystemRoleAuthority();

            if (count > 0)
            {
                for (int j = 0; j < countAuthList; j++)
                {
                    sra        = getAllAuthList[j];
                    sra.IsLock = 0;
                    sral.UpdateRoleAuth(sra);
                }
                for (int i = 0; i < count; i++)
                {
                    string moduleName = lbSelModuleList.Items[i].ToString();
                    //查询roleId和moduleName相同的对象,修改IsLock为1
                    sra        = sral.GetRoleIdAndModule(roleId, moduleName);
                    sra.IsLock = 1;
                    sral.UpdateRoleAuth(sra);
                }
            }
        }
 public void Add(SystemRoleAuthority roleAuth)
 {
     if (roleAuth != null)
     {
         _dbContext.SystemRoleAuthorities.Add(roleAuth);
     }
 }
Example #3
0
        private void btnEnter_Click(object sender, EventArgs e)
        {
            if (this.Text == "修改角色")
            {
                sr.RoleName        = tbRoleName.Text.Trim();
                sr.RoleDescription = tbRoleDescription.Text.Trim();
                //将数据保存到数据库中
                if (srl.Update(sr) == 1)
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK);
                }
                else
                {
                    MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK);
                }
            }
            else if (this.Text == "新建角色")
            {
                //插入一条角色记录
                if (tbRoleName.Text != string.Empty && tbRoleDescription.Text != string.Empty)
                {
                    SystemRole sr = new SystemRole();
                    sr.RoleName        = tbRoleName.Text.Trim();
                    sr.RoleDescription = tbRoleDescription.Text.Trim();
                    if (srl.Add(sr) == 1)
                    {
                        //返回最后一行记录


                        //循环写入权限模块表,并将其属性IsLock设置为0
                        //查询模块列表
                        //写入数据库
                        foreach (var item in sml.GetAllModule())
                        {
                            SystemRoleAuthority sra = new SystemRoleAuthority()
                            {
                                RoleId     = srl.RoleId(),
                                ModuleName = item.TopName,
                                IsLock     = 0
                            };
                            sral.AddRoleAuthority(sra);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请填写完整的角色信息", "提示", MessageBoxButtons.OK);
                }
            }
            //刷新数据列表
            frmSystemSetting fss;

            fss = (frmSystemSetting)this.Owner;
            fss.RefreshMethod();
            this.Close();
        }
        public void Update(SystemRoleAuthority roleAuth)
        {
            var role = _dbContext.SystemRoleAuthorities.Find(roleAuth.Id);

            if (role != null)
            {
                role.RoleId     = roleAuth.RoleId;
                role.ModuleName = roleAuth.ModuleName;
                role.IsLock     = roleAuth.IsLock;
            }
        }
Example #5
0
 public int AddRoleAuthority(SystemRoleAuthority roleAuth)
 {
     if (roleAuth != null)
     {
         sras.Add(roleAuth);
         int result = sras.SaveChanges();
         return(result);
     }
     else
     {
         return(0);
     }
 }
Example #6
0
 public int UpdateRoleAuth(SystemRoleAuthority roleAuth)
 {
     if (roleAuth != null)
     {
         sras.Update(roleAuth);
         int result = sras.SaveChanges();
         return(result);
     }
     else
     {
         return(0);
     }
 }
Example #7
0
        public void testUpdate()
        {
            SystemRoleAuthorityService sras = new SystemRoleAuthorityService();
            SystemRoleAuthority        sra  = new SystemRoleAuthority();

            sra.Id         = 1;
            sra.ModuleName = "客户";
            sra.RoleId     = 1;
            sra.IsLock     = 0;
            sras.Update(sra);
            sras.SaveChanges();
            Assert.IsTrue(sra.IsLock == sras.GetRoleAuth(1).IsLock);
            Console.WriteLine(sras.GetRoleAuth(1).IsLock);
        }