public async Task <bool> SignUpStudentAsync(string studentId, int courseId) { CourseWithStudentServiceModel model = await this.GetCourseWithStudentInfoAsync(studentId, courseId); if (model == null || model.StartDate < DateTime.UtcNow || model.IsStudentEnrolledInCourse) { return(false); } StudentCourse studentCourse = new StudentCourse { StudentId = studentId, CourseId = courseId }; this.database.Add(studentCourse); await this.database.SaveChangesAsync(); return(true); }
public async Task <bool> SignOutStudentAsync(string studentId, int courseId) { CourseWithStudentServiceModel model = await this.GetCourseWithStudentInfoAsync(studentId, courseId); if (model == null || model.StartDate < DateTime.UtcNow || !model.IsStudentEnrolledInCourse) { return(false); } //StudentCourse studentCourse = await this.database // .Courses // .Where(c => c.Id == courseId) // .SelectMany(c => c.Students) // .Where(s => s.StudentId == studentId) // .FirstOrDefaultAsync(); StudentCourse studentCourse = await this.database.FindAsync <StudentCourse>(studentId, courseId); this.database.Remove(studentCourse); await this.database.SaveChangesAsync(); return(true); }