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); } }
public async Task CreateChallenge(Challenge challenge) { using (db = new AthenaDataContext()) { db.Challenges.Add(challenge); await db.SaveChangesAsync(); } }
public async Task CreateCourse(Course course) { using (db = new AthenaDataContext()) { db.Courses.Add(course); await db.SaveChangesAsync(); } }
public async Task <IEnumerable <Course> > GetAllCourses() { using (db = new AthenaDataContext()) { var courses = await db.Courses .OrderByDescending(c => c.DateCreated).ToListAsync(); return(courses); } }
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); } }
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); } }
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); } }
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); } }
public async Task <Course> FindCourse(Guid id) { using (db = new AthenaDataContext()) { var course = await db.Courses .Where(c => c.Id == id) .FirstOrDefaultAsync(); return(course); } }
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); } }
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); } }
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); } }
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(); } }