예제 #1
0
        public async Task <IActionResult> Create([Bind("FirstMidName,HireDate,LastName,OfficeAssignment")] Lecturer lecturer, string[] selectedCourses)
        {
            if (selectedCourses != null)
            {
                lecturer.CourseAssignments = new List <CourseAssignment>();
                foreach (var course in selectedCourses)
                {
                    var courseToAdd = new CourseAssignment {
                        LecturerID = lecturer.ID, CourseID = int.Parse(course)
                    };

                    lecturer.CourseAssignments.Add(courseToAdd);
                }
            }
            if (ModelState.IsValid)
            {
                _context.Add(lecturer);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            PopulateAssignedCourseData(lecturer);

            return(View(lecturer));
        }
        public async Task <IActionResult> Create([Bind("ID,LastName,FirstMidName,EnrollmentDate")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(student));
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("ID,Forenames,Surname,Email,DateOfBirth")] Lecturer lecturer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lecturer);
                await _context.SaveChangesAsync();

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

                return(RedirectToAction(nameof(Index)));
            }
            return(View(course));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("DegreeID,ID,Forenames,Surname,Email,DateOfBirth")] Student student)
        {
            if (ModelState.IsValid)
            {
                _context.Add(student);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DegreeID"] = new SelectList(_context.Degrees, "DegreeID", "DegreeID", student.DegreeID);
            return(View(student));
        }
예제 #6
0
        public async Task <IActionResult> Create([Bind("DegreeID,DegreeName,DegreeDuration,LecturerID")] Degree degree)
        {
            if (ModelState.IsValid)
            {
                _context.Add(degree);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LecturerID"] = new SelectList(_context.Lecturers, "ID", "Email", degree.LecturerID);
            return(View(degree));
        }
예제 #7
0
        public async Task <IActionResult> Create([Bind("CourseID,Credits,DepartmentID,Title")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            PopulateDepartmentsDropDownList(course.DepartmentID);
            return(View(course));
        }
예제 #8
0
        public async Task <IActionResult> Create([Bind("CourseID,DegreeID,CourseName,CourseDuration")] Course course)
        {
            if (ModelState.IsValid)
            {
                _context.Add(course);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DegreeID"] = new SelectList(_context.Degrees, "DegreeID", "DegreeID", course.DegreeID);
            return(View(course));
        }
예제 #9
0
        public async Task <IActionResult> Create([Bind("EnrollmentID,CourseID,StudentID,Grade")] Enrollment enrollment)
        {
            if (ModelState.IsValid)
            {
                _context.Add(enrollment);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CourseID"]  = new SelectList(_context.Courses, "CourseID", "CourseID", enrollment.CourseID);
            ViewData["StudentID"] = new SelectList(_context.Students, "ID", "ID", enrollment.StudentID);
            return(View(enrollment));
        }
예제 #10
0
        public async Task <IActionResult> Create([Bind("DepartmentID,Name,Budget,StartDate,LecturerID,RowVersion")] Department department)
        {
            if (ModelState.IsValid)
            {
                _context.Add(department);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ViewData["LecturerID"] = new SelectList(_context.Lecturers, "ID", "FullName", department.LecturerID);

            return(View(department));
        }
예제 #11
0
        public async Task <IActionResult> Create([Bind("LastName,FirstMidName,EnrollmentDate,DOB")] Student student)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(student);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(student));
        }
 public IActionResult AddCourse([FromBody] Course course)
 {
     context.Add(course);
     context.SaveChanges();
     return(Ok());
 }