public async Task <ObjectResponse <IEnumerable <StudentUser> > > GetStudentList() { try { var students = (await _ivySchoolRepository.GetStudents().ToListAsync()).Select(ConvertToStudentUser); return(ObjectResponse <IEnumerable <StudentUser> > .Success(students)); } catch (DBOperationException ex) { return(ObjectResponse <IEnumerable <StudentUser> > .Error(ex.Message)); } }
public async Task <SimpleResponse> EnrolledCourse(int studentId, int courseId) { if (!_ivySchoolRepository.GetStudents().Any(x => x.StudentId == studentId)) { return(SimpleResponse.Error("StudentId cannot be empty")); } if (_ivySchoolRepository.GetCourseById(courseId) == null) { return(SimpleResponse.Error("CourseId cannot be empty")); } try { await _ivySchoolRepository.StudentEnrollCourse(studentId, courseId); } catch (DBOperationException ex) { return(SimpleResponse.Error(ex.Message)); } return(SimpleResponse.Success()); }