예제 #1
0
        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);
        }
예제 #2
0
        public void DeleteGlobalArrayItem(string customerId, int graphId, string propArray, int itemId)
        {
            var graph = _context.DataGraph.First(i => i.CustomerId == customerId && i.Id == graphId);

            if (graph.Schema.Global.TryGetProperty(propArray, out DataGraphProperty prop))
            {
                if (prop.IsArray)
                {
                    // Check it's actually in that specified collection
                    var reference = _context.ListOfReferences.FirstOrDefault(i =>
                                                                             i.CustomerId == customerId &&
                                                                             i.GraphId == graphId &&
                                                                             i.ObjectId == graph.GlobalObjectId &&
                                                                             i.PropertyName == prop.Name &&
                                                                             i.ReferencedObjectId == itemId);

                    if (reference != null)
                    {
                        _context.ListOfReferences.Remove(reference);
                        _context.SaveChanges();
                    }
                    else
                    {
                        throw new KeyNotFoundException();
                    }
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
        }