public async Task CreateInstructor(InstructorWithCoursesIn instructorWithCoursesIn) { Instructor instructor = EntityAssemblerFactory <Instructor, InstructorWithCoursesIn> .CreateAssembler().AssembleEntity(instructorWithCoursesIn); List <Course> existingCourseList = new List <Course>(); foreach (var course in instructor.Courses) { existingCourseList.Add(await LoadExistingCourseAsync(c => c.Id == course.Id, course.Id)); } instructor.Courses.Clear(); instructor.Courses.AddRange(existingCourseList); _unitOfWork.Instructors.Add(instructor); await _unitOfWork.Complete(); }
public async Task CreateInstructors(IEnumerable <InstructorWithCoursesIn> instructorsWithCoursesIn) { IEnumerable <Instructor> instructors = EntityAssemblerFactory <IEnumerable <Instructor>, IEnumerable <InstructorWithCoursesIn> > .CreateAssembler().AssembleEntity(instructorsWithCoursesIn); List <Course> existingCourseList = new List <Course>(); foreach (Instructor instructor in instructors) { foreach (var course in instructor.Courses) { //Func<Course, bool> predicate = c => c.Id == course.Id; existingCourseList.Add(await LoadExistingCourseAsync(c => c.Id == course.Id, course.Id)); } instructor.Courses.Clear(); instructor.Courses.AddRange(existingCourseList); existingCourseList.Clear(); } _unitOfWork.Instructors.AddRange(instructors); await _unitOfWork.Complete(); }