private async Task <List <ExamModel> > GetExamsData() { var examsData = new List <ExamModel>(); var exams = await _examsRepository.GetExamsList(); if (exams != null && exams.Count > 0) { foreach (var item in exams) { var exam = _mapper.Map <ExamModel>(item); if (item.StudentExams != null && item.StudentExams.Count > 0) { foreach (var record in item.StudentExams) { var student = _mapper.Map <StudentDetails>(record.Student); exam.Students.Add(student); } } examsData.Add(exam); } } return(examsData); }
public async Task <List <ExamModel> > GetExamsList() { try { List <ExamModel> result = new List <ExamModel>(); var exams = await _examsRepository.GetExamsList(); if (exams != null && exams.Count > 0) { foreach (var item in exams) { var exam = _mapper.Map <ExamModel>(item); result.Add(exam); } } return(result); } catch (Exception e) { Console.WriteLine(e); throw; } }