public async Task <IActionResult> EditStudents(int courseId) { var course = _coursesRepository.GetById(courseId); var students = await _studentsRepository.GetActiveStudents(); var subjectId = course.SubjectId; var subject = _subjectsRepository.GetById(subjectId); var model = new CourseEditStudentsViewModel { CourseId = courseId, Course = new CourseViewModel { CourseId = courseId, Description = subject.Description, Start = course.StartDate, End = course.EndDate, Subject = subject, Name = course.Name, Teacher = new UserViewModel { Email = course.Teacher.Email, FirstName = course.Teacher.FirstName, LastName = course.Teacher.LastName, MiddleName = course.Teacher.MiddleName, }, TeacherId = course.TeacherId, SubjectId = subjectId }, }; var studentsInCourse = (await _coursesRepository.GetStudents(model.CourseId)).Select(x => x.StudentId).ToList(); model.Students = students.Select(x => new CourseStudentEditViewModel { Id = x.StudentId, Name = x.User.LastName + " " + x.User.FirstName + " " + x.User.MiddleName, Selected = studentsInCourse.Count == 0 ? false : studentsInCourse.Contains(x.StudentId) }).ToList(); return(View(model)); }