コード例 #1
0
        public async Task <IActionResult> Create([Bind("CourseID,CourseNumber,CourseName,CourseDescription")] Courses courses)
        {
            if (ModelState.IsValid)
            {
                _context.Add(courses);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(courses));
        }
コード例 #2
0
        public async Task <IActionResult> Create([Bind("StudentID,FirstName,LastName,EmailAddress,PhoneNumber")] Students students)
        {
            if (ModelState.IsValid)
            {
                _context.Add(students);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
コード例 #3
0
        public async Task <IActionResult> Create([Bind("InstructorId,FirstName,LastName,EmailAddress")] Instructors instructor, Courses course)
        {
            if (ModelState.IsValid)
            {
                if (course != null)
                {
                    var newCourse = _context.Courses.Where(c => c.CourseID == course.CourseID).SingleOrDefault();

                    instructor.InstructorId = _context.Instructors.AsEnumerable().Last().InstructorId + 1;

                    instructor.Courses = newCourse;
                    _context.Add(instructor);
                    await _context.SaveChangesAsync();

                    // return RedirectToAction(nameof(Index));
                }
            }
            return(RedirectToAction("Index"));
        }