private static bool CanAccessYear(CourseYearDto courseYear, string userId, bool isRoot) { var course = courseYear.CourseConfigDto(); if (isRoot || course.Access == CourseAccess.Public) { return(true); } if (courseYear.AllUsers().Contains(userId)) { return(true); } return(false); }
public List <CourseConfigDto> ToDto(List <Course> courses) { // 3) map to dto var dtos = new List <CourseConfigDto>(); foreach (var course in courses) { var dto = new CourseConfigDto { Name = course.CourseConfig.Name, Desc = course.CourseConfig.Desc, Disabled = course.CourseConfig.Disabled, Access = course.CourseConfig.Access.ParseOrDefault(CourseAccess.Private), Courses = new List <CourseYearDto>(), Errors = course.Errors, CourseDir = course.CourseDir, }; course.CourseYears.ForEach(i => { var courseDto = new CourseYearDto(dto) { Year = i.Year, Teachers = i.SettingsConfig.Teachers, }; courseDto.Problems = i.Problems .Select(j => new ProblemDto(courseDto) { Config = j, }).ToList(); dto.Courses.Add(courseDto); }); dtos.Add(dto); } return(dtos); }
public CourseYearDto CourseYearDto(CourseYearDto item = null) => item == null ? _courseYearDto : _courseYearDto = item;
// -------------------------------------- public ProblemDto(CourseYearDto courseYearDto) { CourseYearDto(courseYearDto); }