示例#1
0
        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));
        }
示例#2
0
        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)));
        }
示例#3
0
        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));
        }
示例#4
0
        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));
        }