// GET: Relationship/StudentLessons public async Task <ActionResult> StudentLessons(string user, long id) { try { Teacher teacher = await _teacherRepositoryAsync.GetByUserAsync(user); List <Student> Students = await _studentRepositoryAsync.ListByUserAsync(user); Student student = await _studentRepositoryAsync.GetByIdAsync(id); List <StudentLesson> studentLessons = student.StudentLessons; List <long> assignedLessons = new List <long>(); foreach (var lesson in studentLessons) { assignedLessons.Add(lesson.LessonId); } RelationshipViewModel model = new RelationshipViewModel { Teacher = teacher, Student = student, StudentLessons = studentLessons, AssignedLessons = assignedLessons }; return(View(model)); } catch (Exception) { throw; } }
// GET: Student public async Task <ActionResult> Index(string user) { Teacher teacherData = await _teacherRepositoryAsync.GetByUserAsync(user); //Somehow adding this List of Students query will change the teacherData query to include StudentLessons (grandchild data), without this, all StudentLessons for Students is null. List <Student> Students = await _studentRepositoryAsync.ListByUserAsync(user); return(View(teacherData)); }