Beispiel #1
0
        /// <summary>
        /// 添加角色的方法
        /// </summary>
        /// <returns></returns>
        public ActionResult ExeAddRole()
        {
            //接收角色名
            string rolename = Request["rolename"];
            //根据角色名称查询角色id
            RoleInfo ri = dal.GetRolebyRoleName(rolename);

            if (ri != null)
            {
                return(Content("1"));
            }
            else
            {
                bool istrue = false;
                if (rolename != null)
                {
                    RoleInfo r = new RoleInfo();
                    r.RoleName = rolename;
                    istrue     = dal.AddRole(r);
                }

                if (istrue)
                {
                    //根据角色名称查询角色id
                    int?roleID = dal.GetIDbyRoleName(rolename);

                    //接收权限ids
                    string ids = Request["nums"];

                    if (roleID != null && ids != null)
                    {
                        //添加角色权限
                        List <string> list  = ids.Split(',').ToList();
                        bool          isAdd = false;
                        for (int i = 0; i < list.Count() - 1; i++)
                        {
                            RoleInfo_PermissionInfo rp = new RoleInfo_PermissionInfo();
                            rp.RoleId       = roleID;
                            rp.PermissionID = Convert.ToInt32(list[i]);

                            isAdd = dal.AddRolePers(rp);
                        }
                        if (isAdd)
                        {
                            return(Content("0"));
                        }
                    }
                }
            }

            return(View("addrole"));
        }