Esempio n. 1
0
        private void SaveRolePermission(System.Web.HttpContext context)
        {
            context.Response.ContentType = "application/json";
            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder("{");
            int roleId = 0;

            try
            {
                roleId = int.Parse(context.Request.Form["roleId"]);
            }
            catch (System.Exception)
            {
                stringBuilder.Append("\"status\":\"0\",\"Desciption\":\"参与错误!\"}");
                context.Response.Write(stringBuilder.ToString());
                return;
            }
            string text = context.Request.Form["rolePermissions"];

            System.Collections.Generic.List <RolePermissionInfo> list = new System.Collections.Generic.List <RolePermissionInfo>();
            if (!string.IsNullOrEmpty(text))
            {
                string[] array = text.Split(new char[]
                {
                    ','
                });
                string[] array2 = array;
                for (int i = 0; i < array2.Length; i++)
                {
                    string permissionId = array2[i];
                    list.Add(new RolePermissionInfo
                    {
                        RoleId       = roleId,
                        PermissionId = permissionId
                    });
                }
            }
            bool flag = ManagerHelper.AddRolePermission(list, roleId);

            if (flag)
            {
                stringBuilder.Append("\"status\":\"1\",\"Desciption\":\"操作成功!\"}");
                context.Response.Write(stringBuilder.ToString());
                return;
            }
            stringBuilder.Append("\"status\":\"1\",\"Desciption\":\"操作成功,该部门未设置任何权限!\"}");
            context.Response.Write(stringBuilder.ToString());
        }
        private void SaveRolePermission(HttpContext context)
        {
            context.Response.ContentType = "application/json";
            StringBuilder builder = new StringBuilder("{");
            int           roleId  = 0;

            try
            {
                roleId = int.Parse(context.Request.Form["roleId"]);
            }
            catch (Exception)
            {
                builder.Append("\"status\":\"0\",\"Desciption\":\"参与错误!\"}");
                context.Response.Write(builder.ToString());
                return;
            }
            string str = context.Request.Form["rolePermissions"];
            List <RolePermissionInfo> models = new List <RolePermissionInfo>();

            if (!string.IsNullOrEmpty(str))
            {
                foreach (string str2 in str.Split(new char[] { ',' }))
                {
                    RolePermissionInfo item = new RolePermissionInfo
                    {
                        RoleId       = roleId,
                        PermissionId = str2
                    };
                    models.Add(item);
                }
            }
            if (ManagerHelper.AddRolePermission(models, roleId))
            {
                builder.Append("\"status\":\"1\",\"Desciption\":\"操作成功!\"}");
                context.Response.Write(builder.ToString());
            }
            else
            {
                builder.Append("\"status\":\"1\",\"Desciption\":\"操作成功,该部门未设置任何权限!\"}");
                context.Response.Write(builder.ToString());
            }
        }