public ActionResult AddOrRemoveOntologies() { String json = Request["data"]; var rows = (ArrayList)MiniJSON.Decode(json); foreach (Hashtable row in rows) { //根据记录状态,进行不同的增加、删除、修改操作 String state = row["_state"] != null ? row["_state"].ToString() : ""; var id = new Guid(row["Id"].ToString()); if (state == "modified" || state == "") //更新:_state为空或modified { bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); NodeOntologyCare entity = GetRequiredService <IRepository <NodeOntologyCare> >().GetByKey(id); if (entity != null) { if (!isAssigned) { AcDomain.RemoveNodeOntologyCare(AcSession, id); } } else if (isAssigned) { AcDomain.Handle(new NodeOntologyCareCreateInput { Id = id, NodeId = new Guid(row["NodeId"].ToString()), OntologyId = new Guid(row["OntologyId"].ToString()) }.ToCommand(AcSession)); } } } return(this.JsonResult(new ResponseData { success = true })); }
public ActionResult AddOrRemoveNodes() { 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() : ""; if (state == "modified" || state == "") //更新:_state为空或modified { var inputModel = new NodeOntologyCareCreateInput() { Id = new Guid(row["Id"].ToString()), NodeId = new Guid(row["NodeId"].ToString()), OntologyId = new Guid(row["OntologyId"].ToString()) }; bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); NodeOntologyCare entity = GetRequiredService <IRepository <NodeOntologyCare, Guid> >().GetByKey(inputModel.Id.Value); bool isNew = true; if (entity != null) { isNew = false; if (!isAssigned) { GetRequiredService <IRepository <NodeOntologyCare, Guid> >().Remove(entity); } } else { Debug.Assert(inputModel.Id != null, "inputModel.Id != null"); entity = new NodeOntologyCare(inputModel.Id.Value) { OntologyId = inputModel.OntologyId, NodeId = inputModel.NodeId }; } if (isAssigned) { if (isNew) { var count = GetRequiredService <IRepository <NodeOntologyCare, Guid> >().AsQueryable().Count(a => a.OntologyId == entity.OntologyId && a.NodeId == entity.NodeId); if (count > 0) { throw new ValidationException("给定的节点已关心给定的本体,无需重复关心"); } GetRequiredService <IRepository <NodeOntologyCare, Guid> >().Add(entity); } else { GetRequiredService <IRepository <NodeOntologyCare, Guid> >().Update(entity); } GetRequiredService <IRepository <NodeOntologyCare, Guid> >().Context.Commit(); } } } return(this.JsonResult(new ResponseData { success = true })); }