0

I am trying to implement a organizational structure where one user can have more than one children users and parent users. Using cosmosDB as document database, I have stored the path of parent users in each user document.

Data Structure of user document

user1
path = null

user2
path = ["user1ID"]

user3
path = ["user2ID", "user1ID"]

user4
path = [["user1ID"], ["user3ID", "user2ID", "user1ID"]]

where path is List<List<string>>()

Problem: I wrote logic to update the paths of the users and find the flat list of ascendants and descendants of a user. The problem I am facing is to represent these list of users in hierarchy.

Output expected:

user1 -> 
        user2->
               user3->
                      user4
        user4

user2 -> 
        user3 ->
                user4

user3 -> 
        user4

user4 ->

In front-end, i am using JsTree library to show the user hierarchies.

I looked for many solutions regarding this but couldn't find the way i am looking for. Any help would be appreciated.

Bijay Kushawaha
  • 172
  • 2
  • 12
  • why you want to save it as a flat list? you can save correct hierarchy and that's it – Olha Shumeliuk Jun 12 '18 at 17:36
  • if u are sure u want flat, you can save in next format: create list of items with data (name, title) and its parentElement. From this info - you can always recreate tree structure – Olha Shumeliuk Jun 12 '18 at 17:40
  • @OlgaShumeliuk I understood your points. But in case having single parent, we can use tree helper library of C# to represent the tree hierarchy and can be used in JS Tree for client side to show the data in tree structure. But here the case is one child can have more than one parents. I want to find out the correct hierarchy rather than flat list. But not being able to write the logic. Could you please render some more ideas in my case. I want to use my data structure i.e. paths variable storing List> type of value as shown above. – Bijay Kushawaha Jun 15 '18 at 05:14

0 Answers0