private void EnterEditMode(ICommentTree commentTree)
        {
            if (commentTree != null)
            {
                commentTree.IsEditExpanded = !commentTree.IsEditExpanded;

                if (commentTree.IsEditExpanded)
                {
                    commentTree.IsReplyExpanded = false;
                }
            }
        }
        public IEnumerable <ICommentTree> CreateCommentTree(IEnumerable <GitComment> gitComments, char separator = '/')
        {
            Dictionary <long, GitComment> searchableGitComments = new Dictionary <long, GitComment>();

            foreach (var comment in gitComments)
            {
                searchableGitComments.Add(comment.Id, comment);
            }

            Dictionary <int, List <ObjectTree> > result = new Dictionary <int, List <ObjectTree> >();

            var maxLevel = -1;

            foreach (var comment in gitComments)
            {
                var           level = 0;
                List <long>   ids   = new List <long>();
                StringBuilder path  = new StringBuilder();

                ids.Add(comment.Id);
                var tmpComment = comment;
                while (tmpComment.Parent != null)
                {
                    ids.Add(tmpComment.Parent.Id);
                    level++;

                    tmpComment = searchableGitComments[tmpComment.Parent.Id];
                }

                if (!result.ContainsKey(level))
                {
                    result[level] = new List <ObjectTree>();
                    if (level > maxLevel)
                    {
                        maxLevel = level;
                    }
                }

                for (var pathIndex = ids.Count - 1; pathIndex > -1; pathIndex -= 1)
                {
                    path.Append(ids[pathIndex]);

                    if (pathIndex > 0)
                    {
                        path.Append(separator);
                    }
                }

                result[level].Add(new ObjectTree(path.ToString(), new GitComment()
                {
                    Content   = comment.Content,
                    CreatedOn = comment.CreatedOn,
                    Id        = comment.Id,
                    Parent    = comment.Parent,
                    User      = comment.User,
                    UpdatedOn = comment.UpdatedOn,
                    Inline    = comment.Inline,
                    IsDeleted = comment.IsDeleted,
                    Version   = comment.Version
                }));
            }



            ICommentTree entryComment = new CommentTree(null);

            for (var i = 0; i <= maxLevel; i++)
            {
                List <ObjectTree> preparedComments = result[i];
                foreach (var objectTree in preparedComments)
                {
                    ICommentTree currentComment = entryComment;
                    var          pathChunks     = objectTree.Path.Split(separator);
                    foreach (var pathChunk in pathChunks)
                    {
                        var tmp = currentComment.Comments.Where(x => x.Comment.Id.Equals(long.Parse(pathChunk)));
                        if (tmp.Any())
                        {
                            currentComment = tmp.Single();
                        }
                        else
                        {
                            ICommentTree newItem = new CommentTree(objectTree.GitComment);
                            currentComment.Comments.Add(newItem);
                            currentComment = newItem;
                        }
                    }
                }
            }

            return(entryComment.Comments);
        }