Пример #1
0
        public IHttpActionResult GetCourseProgress(string id)
        {
            Course course = _db.Courses.Find(id);

            if (course == null)
            {
                return(NotFound());
            }

            //Calculates progress for all exercises under this course for the current user
            ProgressCourseModel progress = CalculateCourseProgress(id);

            return(Ok(progress));
        }
Пример #2
0
        //Calculates progress for all sections under this course for the current user
        private ProgressCourseModel CalculateCourseProgress(string id)
        {
            ProgressCourseModel progressCourseModel = new ProgressCourseModel();
            var sections = _db.Sections.Where(c => c.CourseId == id).Include(c => c.SectionProgresses);

            progressCourseModel.SectionsNumber = sections.Count();
            if (User is ClaimsPrincipal claimsPrincipal)
            {
                var userId = claimsPrincipal.FindFirst(ClaimTypes.PrimarySid).Value;
                progressCourseModel.SectionsDone =
                    sections.Count(c => c.SectionProgresses.Any(p => p.UserId == userId && p.IsDone));
            }
            return(progressCourseModel);
        }
Пример #3
0
        public IHttpActionResult GetCourseProgress(string id)
        {
            using (var db = new TeachMeBackendContext())
            {
                Course course = db.Courses.Find(id);
                if (course == null)
                {
                    return(NotFound());
                }
            }

            //Calculates progress for all exercises under this course for the current user
            ProgressCourseModel progress = CalculateCourseProgress(id);

            return(Ok(progress));
        }