Beispiel #1
0
        public async Task <UserEnrollment> EnrollUserInCourse(ApplicationUser user, Course course)
        {
            using (db = new AthenaDataContext())
            {
                // first ensure user doesnt have an enrollment for this course already.
                // TODO fix with composite key on context

                var currentEnrollment
                    = await db.UserEnrollments
                      .Where(enrollment => enrollment.CourseId == course.Id &&
                             enrollment.ApplicationUserId == user.Id).FirstOrDefaultAsync();

                if (currentEnrollment == null)
                {
                    currentEnrollment = new UserEnrollment
                    {
                        ApplicationUserId = user.Id,
                        CourseId          = course.Id
                    };

                    db.UserEnrollments.Add(currentEnrollment);
                    await db.SaveChangesAsync();
                }

                return(currentEnrollment);
            }
        }
Beispiel #2
0
 public async Task CreateChallenge(Challenge challenge)
 {
     using (db = new AthenaDataContext())
     {
         db.Challenges.Add(challenge);
         await db.SaveChangesAsync();
     }
 }
Beispiel #3
0
 public async Task CreateCourse(Course course)
 {
     using (db = new AthenaDataContext())
     {
         db.Courses.Add(course);
         await db.SaveChangesAsync();
     }
 }
Beispiel #4
0
        public async Task <IEnumerable <Course> > GetAllCourses()
        {
            using (db = new AthenaDataContext())
            {
                var courses
                    = await db.Courses
                      .OrderByDescending(c => c.DateCreated).ToListAsync();

                return(courses);
            }
        }
Beispiel #5
0
        public async Task <Course> FindCourseByEnrollmentCode(string enrollmentCode)
        {
            using (db = new AthenaDataContext())
            {
                var course
                    = await db.Courses
                      .Where(c => c.EnrollmentCode.ToUpper() == enrollmentCode.Trim().ToUpper()).FirstOrDefaultAsync();

                return(course);
            }
        }
Beispiel #6
0
        public async Task <List <CompletedChallenge> > GetUserCompletedChallenges(ApplicationUser user)
        {
            using (db = new AthenaDataContext())
            {
                var completedChallenges
                    = await db.CompletedChallenges
                      .Where(c => c.ApplicationUserId == user.Id)
                      .ToListAsync();

                return(completedChallenges);
            }
        }
Beispiel #7
0
        public async Task <CompletedChallenge> DetermingUserCompletedChallenge(Challenge challenge, ApplicationUser user)
        {
            using (db = new AthenaDataContext())
            {
                var completedChallenge
                    = await db.CompletedChallenges
                      .Where(c => c.ChallengeId == challenge.Id && c.ApplicationUserId == user.Id)
                      .FirstOrDefaultAsync();

                return(completedChallenge);
            }
        }
Beispiel #8
0
        public async Task <IEnumerable <UserEnrollment> > GetCourseUserEnrollments(Course course)
        {
            using (db = new AthenaDataContext())
            {
                var userEnrollments
                    = await db.UserEnrollments
                      .Where(u => u.CourseId == course.Id).Include(u => u.ApplicationUser)
                      .OrderByDescending(c => c.DateCreated).ToListAsync();

                return(userEnrollments);
            }
        }
Beispiel #9
0
        public async Task <Course> FindCourse(Guid id)
        {
            using (db = new AthenaDataContext())
            {
                var course
                    = await db.Courses
                      .Where(c => c.Id == id)
                      .FirstOrDefaultAsync();

                return(course);
            }
        }
Beispiel #10
0
        public async Task <List <Challenge> > GetAllChallengesByCourse(Course course)
        {
            using (db = new AthenaDataContext())
            {
                var challenges
                    = await db.Challenges
                      .Where(challenge => challenge.CourseId == course.Id)
                      .OrderByDescending(c => c.DateCreated)
                      .ToListAsync();

                return(challenges);
            }
        }
Beispiel #11
0
        public async Task <Challenge> FindChallenge(Guid id)
        {
            using (db = new AthenaDataContext())
            {
                var course
                    = await db.Challenges
                      .Where(c => c.Id == id)
                      .OrderByDescending(c => c.DateCreated)
                      .FirstOrDefaultAsync();

                return(course);
            }
        }
Beispiel #12
0
        public async Task <IEnumerable <Course> > GetEnrolledCoursesByUser(ApplicationUser user)
        {
            using (db = new AthenaDataContext())
            {
                var courses
                    = await db.UserEnrollments
                      .Where(s => s.ApplicationUserId == user.Id)
                      .Include(c => c.Course).Select(m => m.Course)
                      .OrderByDescending(c => c.DateCreated)
                      .ToListAsync();

                return(courses);
            }
        }
Beispiel #13
0
        public async Task CompleteChallenge(Challenge challenge, ApplicationUser user)
        {
            using (db = new AthenaDataContext())
            {
                var previouslyCompleted
                    = await db.CompletedChallenges
                      .Where(c => c.ChallengeId == challenge.Id && c.ApplicationUserId == user.Id)
                      .FirstOrDefaultAsync();

                if (previouslyCompleted != null)
                {
                    return;
                }

                var completedChallenge = new CompletedChallenge
                {
                    ChallengeId       = challenge.Id,
                    ApplicationUserId = user.Id
                };

                db.CompletedChallenges.Add(completedChallenge);
                await db.SaveChangesAsync();
            }
        }