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")); }
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")); }
private Task <int> Persist(CourseAssignment courseAssignment) => _courseAssignmentRepository.Add(courseAssignment);