public ActionResult AddOrUpdateNodeElementActions() { String json = Request["data"]; var rows = (ArrayList)MiniJSON.Decode(json); foreach (Hashtable row in rows) { var id = new Guid(row["Id"].ToString()); //根据记录状态,进行不同的增加、删除、修改操作 String state = row["_state"] != null ? row["_state"].ToString() : ""; //更新:_state为空或modified if (state == "modified" || state == "") { var inputModel = new NodeElementAction() { Id = new Guid(row["Id"].ToString()), NodeId = new Guid(row["NodeId"].ToString()), ElementId = new Guid(row["ElementId"].ToString()), ActionId = new Guid(row["ActionId"].ToString()), IsAllowed = bool.Parse(row["IsAllowed"].ToString()), IsAudit = bool.Parse(row["IsAudit"].ToString()) }; NodeElementAction entity = GetRequiredService <IRepository <NodeElementAction> >().GetByKey(inputModel.Id); if (entity != null) { entity.IsAudit = inputModel.IsAudit; entity.IsAllowed = inputModel.IsAllowed; GetRequiredService <IRepository <NodeElementAction> >().Update(entity); } else { entity = new NodeElementAction(); entity.Id = inputModel.Id; entity.NodeId = inputModel.NodeId; entity.ElementId = inputModel.ElementId; entity.ActionId = inputModel.ActionId; entity.IsAudit = inputModel.IsAudit; entity.IsAllowed = inputModel.IsAllowed; var count = GetRequiredService <IRepository <NodeElementAction> >().AsQueryable().Count(a => a.NodeId == entity.NodeId && a.ElementId == entity.ElementId && a.ActionId == entity.ActionId); if (count > 0) { throw new ValidationException("给定的节点已拥有给定的动作,无需重复关联"); } GetRequiredService <IRepository <NodeElementAction> >().Add(entity); } GetRequiredService <IRepository <NodeElementAction> >().Context.Commit(); AcDomain.CommitEventBus(); } } return(this.JsonResult(new ResponseData { success = true })); }
public ActionResult AddOrUpdateNodeElementActions() { String json = Request["data"]; var rows = (ArrayList)MiniJSON.Decode(json); foreach (Hashtable row in rows) { var id = new Guid(row["Id"].ToString()); //根据记录状态,进行不同的增加、删除、修改操作 String state = row["_state"] != null ? row["_state"].ToString() : ""; //更新:_state为空或modified if (state == "modified" || state == "") { var inputModel = new NodeElementAction() { Id = new Guid(row["Id"].ToString()), NodeId = new Guid(row["NodeId"].ToString()), ElementId = new Guid(row["ElementId"].ToString()), ActionId = new Guid(row["ActionId"].ToString()), IsAllowed = bool.Parse(row["IsAllowed"].ToString()), IsAudit = bool.Parse(row["IsAudit"].ToString()) }; NodeElementAction entity = GetRequiredService<IRepository<NodeElementAction>>().GetByKey(inputModel.Id); if (entity != null) { entity.IsAudit = inputModel.IsAudit; entity.IsAllowed = inputModel.IsAllowed; GetRequiredService<IRepository<NodeElementAction>>().Update(entity); } else { entity = new NodeElementAction(); entity.Id = inputModel.Id; entity.NodeId = inputModel.NodeId; entity.ElementId = inputModel.ElementId; entity.ActionId = inputModel.ActionId; entity.IsAudit = inputModel.IsAudit; entity.IsAllowed = inputModel.IsAllowed; var count = GetRequiredService<IRepository<NodeElementAction>>().AsQueryable().Count(a => a.NodeId == entity.NodeId && a.ElementId == entity.ElementId && a.ActionId == entity.ActionId); if (count > 0) { throw new ValidationException("给定的节点已拥有给定的动作,无需重复关联"); } GetRequiredService<IRepository<NodeElementAction>>().Add(entity); } GetRequiredService<IRepository<NodeElementAction>>().Context.Commit(); AcDomain.CommitEventBus(); } } return this.JsonResult(new ResponseData { success = true }); }