Пример #1
0
 public void Traverse(BinaryTreeModel root)
 {
     if (root == null)
     {
         return;
     }
     Traverse(root.left);
     Traverse(root.right);
 }
Пример #2
0
        private BinaryTreeModel GenerateUserBinary(string userId)
        {
            var user = _context.ApplicationUser.Where(u => u.Id == userId).Select(r => new ApplicationUser
            {
                Id             = r.Id,
                FirstName      = r.FirstName,
                LastName       = r.LastName,
                CreatedOn      = r.CreatedOn,
                UserName       = r.UserName,
                ParentId       = r.ParentId,
                ChildPosition  = r.ChildPosition,
                ReferralsCount = _context.ApplicationUser.Where(u => u.CreatedBy == r.Id).Count()
            }).SingleOrDefault();

            BinaryTreeModel binaryTree = new BinaryTreeModel(userId, user, _context, _userHandler);

            return(binaryTree);
        }
Пример #3
0
        void Load(string userId, BinaryTreeModel tree, ApplicationUser user, ApplicationDbContext context, IUserHandler userHandler)
        {
            var current = user;

            this.userid         = current.Id;
            this.name           = $"{current.FirstName} {current.LastName}";
            this.title          = $"{current.UserName}";
            this.dateregistered = current.CreatedOn.Value.ToString("MM/dd/yyyy");
            this.referrals      = current.ReferralsCount.ToString();
            this.position       = current.ChildPosition.ToString();

            var childs = context.ApplicationUser.Where(c => c.ParentId == current.Id && c.CreatedBy == userId).
                         Select(r => new ApplicationUser
            {
                Id             = r.Id,
                FirstName      = r.FirstName,
                LastName       = r.LastName,
                CreatedOn      = r.CreatedOn,
                UserName       = r.UserName,
                ParentId       = r.ParentId,
                ChildPosition  = r.ChildPosition,
                ReferralsCount = context.ApplicationUser.Where(u => u.CreatedBy == r.Id).Count()
            }).ToList();

            if (childs.Any())
            {
                foreach (var child in childs)
                {
                    if (child.ChildPosition == Enums.BPosition.Left)
                    {
                        this.left = new BinaryTreeModel(userId, child, context, userHandler);
                    }
                    else if (child.ChildPosition == Enums.BPosition.Right)
                    {
                        this.right = new BinaryTreeModel(userId, child, context, userHandler);
                    }
                }
            }
        }