public async Task <StudentDetails> GetStudentDetails(int studentId) { try { var studentDetails = await _students.GetStudentDetails(studentId); var result = _mapper.Map <StudentDetails>(studentDetails); if (studentDetails.StudentExams != null && studentDetails.StudentExams.Count > 0) { foreach (var item in studentDetails.StudentExams) { result.Exams.Add(_mapper.Map <ExamModel>(item.Exam)); } } if (studentDetails.StudentCourses != null && studentDetails.StudentCourses.Count > 0) { foreach (var item in studentDetails.StudentCourses) { result.Courses.Add(_mapper.Map <CourseModel>(item.Course)); } } return(result); } catch (Exception e) { Console.WriteLine(e); throw; } }