private DataGraphObject AddObject(string customerId, int graphId, string userId, DataGraphClass customType, JObject obj) { var newObject = new DataGraphObject { CustomerId = customerId, GraphId = graphId, ObjectType = customType.ClassName, UserId = userId }; foreach (var p in obj.Properties()) { if (customType.TryGetProperty(p.Name, out DataGraphProperty typeProp)) { // Scoping it to simple props right now if (!typeProp.IsCustomType() && !typeProp.IsArray) { AssertTypeMatches(p.Value, typeProp); _context.LiteralPropertyValues.Add(new DataGraphLiteralPropertyValue() { CustomerId = customerId, GraphId = graphId, Object = newObject, PropertyName = typeProp.Name, ProperyValueJson = p.Value.ToString(Newtonsoft.Json.Formatting.None) }); } } } return(newObject); }
public int CreateGraphForCustomer(AuthenticationState authState, string graphName) { var dataGraph = new DataGraphInstance() { CustomerId = authState.User.GetCustomerId(), Name = graphName }; _context.DataGraph.Add(dataGraph); // Configure the global object var globalObj = new DataGraphObject() { UserId = "", ObjectType = "Global", Graph = dataGraph }; _context.Objects.Add(globalObj); _context.SaveChanges(); dataGraph.GlobalObjectId = globalObj.ObjectId; _context.SaveChanges(); // Respond with the graph ID return(dataGraph.Id); }
public void PutForUser(string customerId, int graphId, string path, [FromBody] JToken json) { string userId = AuthUser(); var graph = _context.DataGraph.First(i => i.CustomerId == customerId && i.Id == graphId); var userSchema = graph.Schema.User; if (userSchema.TryGetProperty(path, out DataGraphProperty prop)) { var userObj = _context.Objects.FirstOrDefault(i => i.CustomerId == customerId && i.GraphId == graphId && i.UserId == userId && i.ObjectType == "User"); if (userObj == null) { userObj = new DataGraphObject { CustomerId = customerId, GraphId = graphId, UserId = userId, ObjectType = "User" }; _context.Objects.Add(userObj); // Save changes so we get an ObjectId assigned _context.SaveChanges(); } PutIntoObject(customerId, graphId, userId, userObj.ObjectId, graph.Schema.CustomTypes, prop, json); } else { throw new InvalidOperationException("Unknown property"); } }