public List <LastLessonVM> GetLastLesson(string studentName) { if (studentName == null) { return(new List <LastLessonVM>()); } IEnumerable <User> students = usersRepo.UsersByUsersname(studentName); List <LastLessonVM> viewModel = new List <LastLessonVM>(); WeekDays weekDay = schedRepo.GetCurrentDay(); foreach (User student in students) { Schedule lastLesson = schedRepo.LastLesson(student.Id, weekDay); if (lastLesson != null) { viewModel.Add(new LastLessonVM { Student = new PartialUserVM { Id = student.Id, FirstName = student.FirstName, LastName = student.LastName }, SubjectName = lastLesson.Course.Subject.Name, ClassroomName = lastLesson.Classroom.Name, ClassroomLocation = lastLesson.Classroom.Location, EndingTime = lastLesson.EndingTime }); } } return(viewModel); }