Skip to content

Commit 06120f4

Browse files
committed
refactor: use linq.aggregate
1 parent 29a0225 commit 06120f4

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

HwProj.CoursesService/HwProj.CoursesService.API/Services/CourseFilterService.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,16 @@ public async Task<CourseDTO> ApplyFilter(CourseDTO course, string userId)
9797

9898
if (!isMentor)
9999
{
100-
var studentCourse = course;
101-
if (courseFilters.TryGetValue(GlobalFilterId, out var groupFilter))
102-
studentCourse = ApplyFilterInternal(course, studentCourse, groupFilter,
103-
ApplyFilterOperation.Subtract);
104-
105-
// Применяем фильтры всех групп студента
106-
foreach (var group in studentGroups)
107-
{
108-
if (courseFilters.TryGetValue(group.Id.ToString(), out var groupCourseFilter))
109-
studentCourse = ApplyFilterInternal(course, studentCourse, groupCourseFilter, ApplyFilterOperation.Union);
110-
}
100+
var globalFilter = courseFilters.GetValueOrDefault(GlobalFilterId);
101+
var globalCourse = globalFilter != null
102+
? ApplyFilterInternal(course, course, globalFilter, ApplyFilterOperation.Subtract)
103+
: course;
104+
105+
var studentCourse = studentGroups
106+
.Select(g => courseFilters.GetValueOrDefault(g.Id.ToString()))
107+
.Where(cf => cf != null)
108+
.Aggregate(globalCourse, (current, groupCourseFilter) =>
109+
ApplyFilterInternal(course, current, groupCourseFilter, ApplyFilterOperation.Union));
111110

112111
var mentorIds = course.MentorIds
113112
.Where(u =>

0 commit comments

Comments
 (0)