public ActionResult AddOrRemoveElementCares() { 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()); NodeElementCare entity = GetRequiredService <IRepository <NodeElementCare> >().GetByKey(id); if (entity != null) { if (!isAssigned) { AcDomain.RemoveNodeElementCare(AcSession, id); } else { // TODO:IsInfoIDItem字段需要update } } else if (isAssigned) { AcDomain.Handle(new NodeElementCareCreateInput { Id = id, NodeId = new Guid(row["NodeId"].ToString()), ElementId = new Guid(row["ElementId"].ToString()), IsInfoIdItem = bool.Parse(row["IsInfoIDItem"].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 NodeElementCare() { Id = new Guid(row["Id"].ToString()), NodeId = new Guid(row["NodeId"].ToString()), ElementId = new Guid(row["ElementId"].ToString()) }; bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); NodeElementCare entity = GetRequiredService <IRepository <NodeElementCare> >().GetByKey(inputModel.Id); bool isNew = true; if (entity != null) { isNew = false; if (!isAssigned) { GetRequiredService <IRepository <NodeElementCare> >().Remove(entity); } else { } } else { entity = new NodeElementCare { Id = inputModel.Id }; } if (isAssigned) { entity.NodeId = inputModel.NodeId; entity.ElementId = inputModel.ElementId; if (isNew) { var count = GetRequiredService <IRepository <NodeElementCare> >().AsQueryable().Count(a => a.ElementId == entity.ElementId && a.NodeId == entity.NodeId); if (count > 0) { throw new ValidationException("给定的节点已关心给定的本体元素,无需重复关心"); } GetRequiredService <IRepository <NodeElementCare> >().Add(entity); } else { GetRequiredService <IRepository <NodeElementCare> >().Update(entity); } } GetRequiredService <IRepository <NodeElementCare> >().Context.Commit(); } } 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 NodeElementCare() { Id = new Guid(row["Id"].ToString()), NodeId = new Guid(row["NodeId"].ToString()), ElementId = new Guid(row["ElementId"].ToString()) }; bool isAssigned = bool.Parse(row["IsAssigned"].ToString()); NodeElementCare entity = GetRequiredService<IRepository<NodeElementCare>>().GetByKey(inputModel.Id); bool isNew = true; if (entity != null) { isNew = false; if (!isAssigned) { GetRequiredService<IRepository<NodeElementCare>>().Remove(entity); } else { } } else { entity = new NodeElementCare {Id = inputModel.Id}; } if (isAssigned) { entity.NodeId = inputModel.NodeId; entity.ElementId = inputModel.ElementId; if (isNew) { var count = GetRequiredService<IRepository<NodeElementCare>>().AsQueryable().Count(a => a.ElementId == entity.ElementId && a.NodeId == entity.NodeId); if (count > 0) { throw new ValidationException("给定的节点已关心给定的本体元素,无需重复关心"); } GetRequiredService<IRepository<NodeElementCare>>().Add(entity); } else { GetRequiredService<IRepository<NodeElementCare>>().Update(entity); } } GetRequiredService<IRepository<NodeElementCare>>().Context.Commit(); } } return this.JsonResult(new ResponseData { success = true }); }