Ejemplo n.º 1
0
        public CourseIndex GetCourseIndex(Guid id, Guid?userId, Role loggedUserRole)
        {
            var courseIndex     = new CourseIndex();
            var classRepository = new ClassRepository(_context);


            courseIndex.Course      = _context.GetList <Course>().Find(id);
            courseIndex.ClassesInfo = courseIndex.Course.Classes.Where(a => a.Active)
                                      .OrderBy(x => x.Order)
                                      .Select(a => new ClassInfo
            {
                Class      = a,
                Available  = userId.HasValue && classRepository.CheckClassAvailability(a.Id, userId.Value),
                Percentual =
                    userId.HasValue ? a.Accesses.LastOrDefault(x => x.User.Id == userId)?.Percentual ?? 0 : 0,
                Editable = classRepository.CheckClassEditable(a, userId, loggedUserRole)
            });

            return(courseIndex);
        }
Ejemplo n.º 2
0
        public void UpdateWithClasses(Course course)
        {
            var currentCourse = GetById(course.Id);

            course.CreatedAt              = currentCourse.CreatedAt;
            currentCourse.Subject         = course.Subject;
            currentCourse.TeacherInCharge = course.TeacherInCharge;
            course.Classes = currentCourse.Classes;
            _context.Update(currentCourse, course);

            if (course.Active)
            {
                return;
            }
            var classRepository = new ClassRepository(_context);

            foreach (var klass in course.Classes)
            {
                klass.Active = false;
                classRepository.Update(klass);
            }
        }