where first Item is children with path (doesn't matter) and second Item is some departments without any children. Then I get subjects for Item1 and Item2 and fill dataSet with them. My problem: it looks ugly, 2 calls of function
GetByDepartmentsIds
GetByDepartmentsIds
instead of just one Let's see my code:
// returns Dictionary<string, string> and IEnumerable<string> as I said beforevar departments = await GetDepartmentsWithNested();// get subjects and than simple grouping var groupedSubjects = (await _subjectClient .GetByDepartmentsIds(departments.Item1.Keys) .Unwrap() .GroupBy(subject => ( DepartmentId: subject.Department.Id, Title: departments.Item1[subject.Department.Id]));// fill dataset with dataforeach(var group in groupedSubjects) foreach(var subject in group){ dataSet.Staff.AddStaffRow( Title: subject.GetSubjectFullName(), AccessGroup: GetAccessGroupFormattedString(subject.AccessGroups), TabNumber: subject.Data.FromJson<SubjectData>()?.PersonnelNumber, Identifier: GetIdentifierFormattedString(subject.Identifiers), Department: group.Key.Title);}
// returns Dictionary<string, string> and IEnumerable<string> as I said beforevar departments = await GetDepartmentsWithNested();// get subjects and than simple grouping var groupedSubjects = (await _subjectClient .GetByDepartmentsIds(departments.Item1.Keys) .Unwrap() .GroupBy(subject => ( DepartmentId: subject.Department.Id, Title: departments.Item1[subject.Department.Id]));// fill dataset with dataforeach(var group in groupedSubjects) foreach(var subject in group){ dataSet.Staff.AddStaffRow( Title: subject.GetSubjectFullName(), AccessGroup: GetAccessGroupFormattedString(subject.AccessGroups), TabNumber: subject.Data.FromJson<SubjectData>()?.PersonnelNumber, Identifier: GetIdentifierFormattedString(subject.Identifiers), Department: group.Key.Title);}
Okey, now we need to get subjects for Item2 with another grouping!
var anotherGroupedSubjects = (await _subjectClient .GetByDepartmentsIds(departments.Item2) .Unwrap() .GroupBy(subject => subject.Department.Title);foreach(var group in anotherGroupedSubjects) foreach(var subject in group){ dataSet.Staff.AddStaffRow( Title: subject.GetSubjectFullName(), AccessGroup: GetAccessGroupFormattedString(subject.AccessGroups), TabNumber: subject.Data.FromJson<SubjectData>()?.PersonnelNumber, Identifier: GetIdentifierFormattedString(subject.Identifiers), Department: group.Key);}
var anotherGroupedSubjects = (await _subjectClient .GetByDepartmentsIds(departments.Item2) .Unwrap() .GroupBy(subject => subject.Department.Title);foreach(var group in anotherGroupedSubjects) foreach(var subject in group){ dataSet.Staff.AddStaffRow( Title: subject.GetSubjectFullName(), AccessGroup: GetAccessGroupFormattedString(subject.AccessGroups), TabNumber: subject.Data.FromJson<SubjectData>()?.PersonnelNumber, Identifier: GetIdentifierFormattedString(subject.Identifiers), Department: group.Key);}
May someone help me with grouping these things, please?