C#C
C#3y ago
SWEETPONY

✅ How to group nested departments?

First of all I wanna show structure of departments:

FIRST OFFICE
| first room
| second room
| third room ( nested of second room )

SECOND OFFICE
| first room
| second room
| third room ( nested of second room )

okey, each office and each room has id, title and parent_id
for example, third_room will have parent_id == second room.id

if parent_id == null, this is root!

so I have following code:
var nestedDepartments = ( await _departmentClient
    .GetByParentsIds( _parameters.DepartmentIDs )
    .Unwrap() );


it will return all departments with id, parent_id but without any grouping and I don't understand how to group

I have GetByParentId function so I can write this:
List<(string, IList<DepartmentDto>)> departments = new();
foreach ( var id in _parameters.DepartmentIDs )
 {
     var department = await _departmentClient
           .GetByParentId( id )
           .Unwrap();

     departments.Add( (id, department) );
}


So I need the same but with GetByParentsIds function
Was this page helpful?