public async Task <IActionResult> EnrollStudents(int id, EnrollStudentsViewModel 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))); } return(View(viewModel)); }
public async Task <IActionResult> Create([Bind("CourseID,Title,Credits,Semestar,Programme,EducationLevel,FirstTeacherId,SecondTeacherId")] Course course) { _context.Add(course); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
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("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)); }