コード例 #1
0
        public IActionResult CreatePost(CreateInstructorViewModel model)
        {
            if (ModelState.IsValid)
            {
                _instructorRepository.Add(model.Instructor);

                var instructorId = model.Instructor.InstructorId;

                var courseAssignment = new List <CourseAssignment>();

                if (model.AssignedCourseData != null)
                {
                    foreach (var data in model.AssignedCourseData)
                    {
                        if (data.Assigned)
                        {
                            //courseAssignment.Add(new CourseAssignment(){CourseId = data.CourseId,InstructorId = instructorId});
                            _courseAssignmentRepository.Add(new CourseAssignment()
                            {
                                CourseId = data.CourseId, InstructorId = instructorId
                            });
                        }
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View("Create"));
        }
コード例 #2
0
        public IActionResult CreatePost(EditCreateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(NotFound());
            }

            if (model.Instructor != null)
            {
                _instructorRepository.Add(model.Instructor);

                var instructorId = model.Instructor.InstructorId;

                foreach (var data in model.AssignedCourseData)
                {
                    if (data.Assigned)
                    {
                        _courseAssignmentRepository.Add(new CourseAssignment()
                        {
                            CourseId     = data.CourseId,
                            InstructorId = instructorId
                        });
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View("Create"));
        }
コード例 #3
0
 private Task <int> Persist(CourseAssignment courseAssignment) => _courseAssignmentRepository.Add(courseAssignment);