public async Task <IActionResult> Create([Bind("TeacherId,FirstName,LastName,Degree,AcademicRank,OfficeNumber,HireDate")] Teacher teacher)
        {
            if (ModelState.IsValid)
            {
                _context.Add(teacher);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(teacher));
        }
        public async Task <IActionResult> Create([Bind("ID,StudentID,FirstName,LastName,EnrollmentDate,AcquiredCredits,CurrentSemestar,EducationLevel")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
        public async Task <IActionResult> Create([Bind("CourseID,Title,Credits,Semestar,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["FirstTeacherId"]  = new SelectList(_context.Teacher, "TeacherId", "FirstName", course.FirstTeacherId);
            ViewData["SecondTeacherId"] = new SelectList(_context.Teacher, "TeacherId", "FirstName", course.SecondTeacherId);
            return(View(course));
        }
 public async Task<IActionResult> EnrollStudents(int id, EnrollStudentsVM viewModel)
 {
     if (ModelState.IsValid)
     
         foreach (var student in viewModel.SelectedStudents)
         {
             Enrollment enrollment = await _context.Enrollment
                 .FirstOrDefaultAsync(m => m.CourseID == id && m.StudentID == student
                 && m.Year == viewModel.selectedYear && m.Semestar == viewModel.selectedSemester);
             if (enrollment == null)
             {
                 enrollment = new Enrollment
                 {
                     CourseID = id,
                     StudentID = student,
                     Year = viewModel.selectedYear,
                     Semestar = viewModel.selectedSemester
                 };
                 _context.Add(enrollment);
             }
         }
         await _context.SaveChangesAsync();
         return RedirectToAction(nameof(CoursesController.Index));
     }