public string Add() { if (string.IsNullOrWhiteSpace(Request["roleId"])) { return "0"; } string[] funcIds = Request["funcIds"] == null ? null : Request["funcIds"].Split(','); AccessModel.Delete(" where RoleID = @0", Request["roleId"]); foreach (string item in funcIds) { AccessModel access = new AccessModel(); access.Roleid = Request["roleId"].ToInt(); access.Funcid = item.ToInt(); access.CreateMan = SysConfig.CurrentUser.Id; access.CreateTime = DateTime.Now; int result = access.Insert().ToInt(); if (result <= 0) { return "0"; } } //记录操作日志 CommonMethod.Log(SysConfig.CurrentUser.Id, "Insert", "Sys_Access"); return "1"; }
/// <summary> /// Role实体和权限字符串 /// </summary> /// <param name="auth"></param> /// <param name="json"></param> /// <returns></returns> public string addRole(string auth, string json) { if (string.IsNullOrEmpty(json)) { return(new MyHttpResult(false, "提交数据错误!").ToString()); } RoleModel model = JsonExtensions.FromJson <RoleModel>(json); int result; //1.判断是新增角色还是编辑角色 if (model.id == 0)//新增 { //1.新增角色 result = model.Insert(); //2.获得该实体的ID model.id = (new RoleBLL()).getByMax().id; } else //编辑 { result = model.Update(); } //2.删除该角色的所有权限 AccessBLL accessbll = new AccessBLL(); accessbll.deleteByRoleId(model.id.ToString()); //3.insert所有权限 if (!string.IsNullOrEmpty(auth)) { foreach (string roleAuth in auth.Split(",".ToCharArray())) { if (roleAuth != "") { AccessModel accessModel = new AccessModel(); accessModel.node_id = int.Parse(roleAuth); accessModel.role_id = model.id; result = accessModel.Insert(); } } } return(new MyHttpResult(result > 0 ? true : false, "").ToString()); }