Beispiel #1
0
        // vo methodite nadolu se gledat samo WebPages za daden User so userId

        // TODO: da se prepravat queries so LINQ Join ( vo slednite 3 metodi)
        // Ili prvo da se izvadat vo HashSet pa potoa da se koristi HashSet::Contains()

        /// <summary>
        /// Metod koj vraka vrednost vistina
        /// dokolku specificiraniot korisnik ima deca
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>bool</returns>
        public bool HasChildren(int userId)
        {
            SessionTree tree = SessionTree.GetSessionInstance();

            if (tree.HasChildrenMap.ContainsKey(this))
            {
                return(tree.HasChildren(this));
            }

            bool hasChildren = false;

            foreach (WebPage page in this.WebPages)
            {
                if (page.RelativeUrl != "#" && UsersWebPage.EntityExists(userId, page.ID))
                {
                    hasChildren = true;
                    break;
                }
                if (page.RelativeUrl == "#" && page.HasChildren(userId))
                {
                    hasChildren = true;
                    break;
                }
            }
            tree.HasChildrenMap.Add(this, hasChildren);
            SessionTree.UpdateSessionInstance(tree);
            return(hasChildren);
        }
Beispiel #2
0
        /// <summary>
        /// Metod vraka lista od jazli na dinamickoto drvo
        /// so elementi - deca na konkreten korisnik (userID)
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>numerirana lista od jazli (IEnumerable(INBOTreeNode))</returns>
        public IEnumerable <INBOTreeNode> GetChildren(int userId)
        {
            SessionTree tree = SessionTree.GetSessionInstance();

            if (tree.GetChildrenMap.ContainsKey(this))
            {
                return(tree.GetChildren(this));
            }

            List <INBOTreeNode>   children = new List <INBOTreeNode>();
            IEnumerable <WebPage> WebPages = this.WebPages;

            WebPages = WebPages.OrderBy(s => s.OrderNumber);
            foreach (WebPage page in WebPages)
            {
                if (page.RelativeUrl != "#" && UsersWebPage.EntityExists(userId, page.ID))
                {
                    children.Add(page);
                }
                if (page.RelativeUrl == "#")
                {
                    if (page.HasChildren(userId))
                    {
                        children.Add(page);
                    }
                }
            }

            tree.GetChildrenMap.Add(this, children);
            SessionTree.UpdateSessionInstance(tree);
            return(children);
        }
Beispiel #3
0
        /// <summary>
        /// Metod vraka lista od jazli na dinamickoto drvo
        /// so elementi - koreni na konkreten korisnik (userID)
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>numerirana lista od jazli (IEnumerable(INBOTreeNode))</returns>
        public IEnumerable <INBOTreeNode> GetRoots(int userId)
        {
            SessionTree tree = SessionTree.GetSessionInstance();

            if (tree.GetRootsMap.ContainsKey(this))
            {
                return(tree.GetRoots(this));
            }

            List <WebPage>      _roots = (Select().Where(w => w.ParentID == null).ToList());
            List <INBOTreeNode> roots  = new List <INBOTreeNode>();

            foreach (WebPage page in _roots)
            {
                roots.Add((INBOTreeNode)page);
            }

            List <INBOTreeNode> result = new List <INBOTreeNode>();

            foreach (WebPage root in roots)
            {
                foreach (WebPage page in root.WebPages)
                {
                    if (page.RelativeUrl == "#" && page.HasChildren(userId))
                    {
                        result.Add(root);
                        break;
                    }
                    if (page.RelativeUrl != "#" && UsersWebPage.EntityExists(userId, page.ID))
                    {
                        result.Add(root);
                        break;
                    }
                }
            }
            tree.GetRootsMap.Add(this, result);
            SessionTree.UpdateSessionInstance(tree);
            return(result);
        }