C#C
C#3y ago
SWEETPONY

✅ How to change property in tree-like objects?

I have list of departments ids:
var departmentsIds = _parameters.ShowSubjectsOfNestedDepartments
      ? await GetDepartmentsIdsWithNested()
      : _parameters.DepartmentIDs;


Then I try to use ids to get subjects:
var groupedSubjects = ( await _subjectClient
      .GetByDepartmentsIds( departmentsIds )
      .Unwrap() )
      .GroupBy( x => x.Department.Title );


groupedSubjects is a list of SubjectDto:
public class SubjectDto
{
   public string Id { get; set; }
   public DepartmentDigestDto Department { get; set; }
}

public class DepartmentDigestDto
{
    [JsonProperty( PropertyName = "id" )]
    [JsonRequired]
    public string Id { get; set; }

    [JsonProperty( PropertyName = "title" )]
    public string Title { get; set; }

    [JsonProperty( PropertyName = "parent_department_id" )]
    public string ParentDepartmentId { get; set; }
}


so for example, we have 3 departments:

office
room1
room2

groupedSubjects will be grouped by "office", "room1", "room2" etc but I want to see smth like this: "office/room1", "office/room2"
Was this page helpful?