public async Task <IActionResult> AddStudentToSubject(int subjectId, int studentId = -1) { if (_subjectService.DoesSubjectBelongsToStudent(subjectId, studentId)) { return(RedirectToAction("IndexTeacher", new { subjectId = subjectId })); } if (studentId != -1) { // studentId checking await _subjectService.AddStudentToSubject(subjectId, studentId); } Teacher teacher = await _authentication.GetCurrentTeacherAsync(); if (!_subjectService.DoesSubjectBelongsToTeacher(subjectId, teacher.Id)) { return(RedirectToAction("IndexTeacher", new { subjectId = subjectId })); } Subject subject = _databaseWorker.GetSubjectById(subjectId); IEnumerable <Student> availableStudents = await _subjectService.GetStudentsWithoutThisSubject(subject); StudentSubjectViewModel model = new StudentSubjectViewModel { Subject = subject, Students = availableStudents }; return(View(model)); }