public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; try { int permissionId = int.Parse(context.Request.Form["permissionId"]); int moduleId = int.Parse(context.Request.Form["moduleId"]); string[] actionIds = context.Request.Form["actions"].Split(new char[]{','}); StringBuilder sbPL = new StringBuilder(); foreach (string actionId in actionIds) { int aid; bool parsed = int.TryParse(actionId, out aid); if (parsed) { CY.GeneralPrivilege.Core.Business.PermissionsList pl = new CY.GeneralPrivilege.Core.Business.PermissionsList(); pl.PModuleID = moduleId; pl.PermissionID = permissionId; pl.ActionID = aid; pl.Save(); sbPL.Append("{plid: '"); sbPL.Append(pl.Id); sbPL.Append("', actionId: '"); sbPL.Append(pl.ActionID); sbPL.Append("'},"); } } if (sbPL.Length > 0) { sbPL.Remove(sbPL.Length - 1, 1); } context.Response.Write("{success: true, pls: [" + sbPL.ToString() + "]}"); } catch (Exception ex) { context.Response.Write("{success: false, msg: '" + ex.Message.Replace("'", "-").Replace("\"", "-") + "'}"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; string result = string.Empty; string PermissionName = context.Request.Params["PermissionName"]; try { CY.GeneralPrivilege.Core.Business.Permission p = new CY.GeneralPrivilege.Core.Business.Permission(); p.PermissionName = PermissionName; p.Save(); pid = p.Id; } catch (Exception ex) { result = "success:false,msg:'权限新增不成功'"; } string moduleTmp = context.Request.Params["Module"]; string actionTmp = context.Request.Params["Action"]; int[] moduleIds = (int[])Newtonsoft.Json.JavaScriptConvert.DeserializeObject(moduleTmp, typeof(int[])); int[][] actions = (int[][])Newtonsoft.Json.JavaScriptConvert.DeserializeObject(actionTmp, typeof(int[][])); try { for (int i = 0; i<moduleIds.Count(); i++) { int[] actiontemp = actions[i]; for (int k = 0; k<actiontemp.Count(); k++) { CY.GeneralPrivilege.Core.Business.PermissionsList pList = new CY.GeneralPrivilege.Core.Business.PermissionsList(); pList.PermissionID = pid; pList.PModuleID = moduleIds[i]; pList.ActionID = actiontemp[k]; pList.Save(); } } result = "{success:true}"; } catch (Exception ex) { result = "{success:false,msg:'"+ex.Message+"'}"; } context.Response.Write(result); }