Ejemplo n.º 1
0
        public dynamic GetNeighbours(string Forest, int?NodeId = null, int Levels = 1, int SkipLevels = 0, string Lang = null)
        {
            var db = new MindContextProvider(Forest);
            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";
            //get the connections
            var connections = db.Context
                              .GetChildConnections(NodeId, user, Levels, SkipLevels, lang)
                              .ToList();
            var ids     = connections.Select(c => c.ToId).ToList();
            var parents = db.Context
                          .GetParentConnections(NodeId, user, Levels, SkipLevels, lang)
                          .ToArray();

            ids.AddRange(parents.Select(c => c.FromId).ToList());
            connections.AddRange(parents);
            //get nodes
            return(new MindResult()
            {
                Connections = connections,
                Nodes = db.Context
                        .Nodes
                        .Include("Permissions")
                        .Include("Texts")
                        .Where(n => ids.Contains(n.Id))
                        .ToArray()
            });
        }
Ejemplo n.º 2
0
        public dynamic GetTrees(string Forest = null, string Lang = null)
        {
            var db    = new MindContextProvider(Forest);
            var trees = new MindResult();

            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";

            //get the tree connections
            trees.Connections = db.Context
                                //.GetChildConnections(null, user, 5, 0, lang)
                                .GetChildConnections(null, user, 2, 0, lang)
                                .ToArray();

            //get tree nodes
            List <long> ids = trees.Connections.Select(c => c.FromId)
                              .Distinct().ToList();

            ids.AddRange(trees.Connections.Select(c => c.ToId));
            trees.Nodes = db.Context.Nodes
                          .Include("Permissions")
                          .Include("Texts")
                          .Where(n => ids.Contains(n.Id))
                          .ToArray();

            //get forest settings //TODO: implement in db
            var settings = new KeyValuePair <string, string>[] {
                new KeyValuePair <string, string>("NodeClasses", ""),
                new KeyValuePair <string, string>("ConnectionClasses", ""),
                new KeyValuePair <string, string>("Css", "")
            };

            return(new { trees = trees, settings = settings });
        }
Ejemplo n.º 3
0
        public dynamic Roles(string Forest)
        {
            var db = new MindContextProvider(Forest);

            return(db.Context
                   .Roles);
        }
Ejemplo n.º 4
0
        public SaveResult SaveChanges(string Forest, JObject saveBundle)
        {
            var db = new MindContextProvider(Forest);

            //TODO: intercept updates: check permissions, if node deleted, which has other connctions, ignore delete of node (delete connection only)

            return(db.SaveChanges(saveBundle));
        }
Ejemplo n.º 5
0
        public dynamic Nodes(string Forest, string Lang = null)
        {
            var db = new MindContextProvider(Forest);
            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";

            var result = db.Context
                         .GetNodes(user, lang)
            ;

            return(result);
        }
Ejemplo n.º 6
0
        public dynamic Connections(string Forest, string Lang = null)
        {
            var db = new MindContextProvider(Forest);
            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";

            var availableNodes = db.Context.GetNodes(user, lang).Select(n => n.Id).ToArray();
            var result         = db.Context
                                 .Connections
                                 .Where(c => availableNodes.Contains(c.FromId))
            ;

            return(result);
        }
Ejemplo n.º 7
0
        public dynamic Test(string Forest, string Lang = null)
        {
            var db = new MindContextProvider(Forest);
            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";

            var result = db.Context
                         .Nodes
                         .Include("Texts")
                         .Include("ConnectionsFrom")
            ;

            return(result);
        }
Ejemplo n.º 8
0
        public dynamic GetNodeLookup(string Forest, int?RootNodeId = null, string Lang = null)
        {
            var db = new MindContextProvider(Forest);
            //prepare parameters
            string user = User.Identity.IsAuthenticated ? User.Identity.Name : null;
            string lang = Lang ?? "%";

            if (!RootNodeId.HasValue)
            {
                //get the root
                RootNodeId = (int?)db.Context
                             .GetChildConnections(null, user, 1, 0, lang)
                             .Select(c => c.FromId)
                             .FirstOrDefault();
            }

            var result = db.Context
                         .NodeLookup(RootNodeId, user, lang)
                         .ToArray()
            ;

            return(result);
        }
Ejemplo n.º 9
0
        public string Metadata(string Forest = null)
        {
            var db = new MindContextProvider(Forest);

            return(db.Metadata());
        }