예제 #1
0
        public void Edit(PocoCourse course)
        {
            if (course.InstructorsId.Count > 0)
            {
                var obj = ctx.Instructor_Course.Find(course.Id);
                foreach (int id in course.InstructorsId)
                {
                    Instructor_Course ic = new Instructor_Course()
                    {
                        id = obj.id,
                        fk_instructorid = id,
                    };

                    ctx.Instructor_Course.Attach(ic);
                    ctx.Entry(ic).State = EntityState.Modified;
                    ctx.SaveChanges();
                }
            }
            if (course.StudentsId.Count > 0)
            {
                var obj = ctx.Student_Course.Find(course.Id);
                foreach (int id in course.StudentsId)
                {
                    Student_Course sc = new Student_Course()
                    {
                        id           = obj.id,
                        fk_studentid = id,
                        fk_courseid  = course.Id
                    };
                    ctx.Entry(sc).State = EntityState.Modified;

                    ctx.SaveChanges();
                }
            }
        }
예제 #2
0
 public void Add(Course newCourse, PocoCourse course)
 {
     if (course.InstructorsId != null)
     {
         foreach (int id in course.InstructorsId)
         {
             Instructor_Course ic = new Instructor_Course()
             {
                 fk_instructorid = id,
                 fk_courseid     = newCourse.id
             };
             ctx.Instructor_Course.Add(ic);
             ctx.SaveChanges();
         }
     }
     if (course.StudentsId != null)
     {
         foreach (int id in course.StudentsId)
         {
             Student_Course sc = new Student_Course()
             {
                 fk_studentid = id,
                 fk_courseid  = newCourse.id
             };
             ctx.Student_Course.Add(sc);
             ctx.SaveChanges();
         }
     }
 }
예제 #3
0
        public void Add(Course c, POCOCourse pocoCourse)
        {
            if (pocoCourse.StudentsId != null)
            {
                foreach (int id in pocoCourse.StudentsId)
                {
                    Student_Course sc = new Student_Course()
                    {
                        student_id = id,
                        course_id  = c.id
                    };

                    db.Student_Course.Add(sc);
                    db.SaveChanges();
                }
            }

            if (pocoCourse.InstructorsId != null)
            {
                foreach (int id in pocoCourse.InstructorsId)
                {
                    Instructor_Course ic = new Instructor_Course()
                    {
                        instructor_id = id,
                        course_id     = c.id
                    };

                    db.Instructor_Course.Add(ic);
                    db.SaveChanges();
                }
            }
        }
예제 #4
0
 public void Add(Instructor x, PocoInstructor instructor)
 {
     foreach (int id in instructor.CoursesId)
     {
         Instructor_Course ic = new Instructor_Course()
         {
             fk_courseid     = id,
             fk_instructorid = x.Id,
         };
         ctx.Instructor_Course.Add(ic);
         ctx.SaveChanges();
     }
 }
예제 #5
0
        public void Add(Instructor inst, POCOInstructor pocoInstructor)
        {
            if (pocoInstructor.CourseId != null)
            {
                foreach (int id in pocoInstructor.CourseId)
                {
                    Instructor_Course ic = new Instructor_Course()
                    {
                        course_id     = id,
                        instructor_id = inst.id
                    };

                    db.Instructor_Course.Add(ic);
                    db.SaveChanges();
                }
            }
        }