コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("CourseID,CourseNumber,CourseName,CourseDescription")] Courses courses)
        {
            if (id != courses.CourseID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(courses);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CoursesExists(courses.CourseID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(courses));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("StudentID,FirstName,LastName,EmailAddress,PhoneNumber")] Students students)
        {
            if (id != students.StudentID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(students);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!StudentsExists(students.StudentID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(students));
        }
コード例 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("InstructorId,FirstName,LastName,EmailAddress,CourseName")] Instructors instructors, Courses course)
        {
            if (id != instructors.InstructorId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (course != null)
                    {
                        var newCourse = _context.Courses.Where(c => c.CourseID == course.CourseID).SingleOrDefault();

                        instructors.Courses = newCourse;
                    }
                    _context.Update(instructors);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!InstructorsExists(instructors.InstructorId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(instructors));
        }