예제 #1
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();
     }
 }
예제 #2
0
        public IHttpActionResult PostInstructor(PocoInstructor instructor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (instructor.CoursesId != null)
            {
                Instructor newInstructor = new Instructor()
                {
                    name      = instructor.Name,
                    phone     = instructor.Phone,
                    mail      = instructor.Mail,
                    dept      = instructor.Dept,
                    isDeleted = false,
                };
                Instructor x = db.Instructor.Add(newInstructor);
                db.SaveChanges();
                ctx.Add(x, instructor);

                return(CreatedAtRoute("DefaultApi", new { id = x.Id }, newInstructor));
            }
            else
            {
                Instructor newInstructor = new Instructor()
                {
                    name      = instructor.Name,
                    phone     = instructor.Phone,
                    mail      = instructor.Mail,
                    dept      = instructor.Dept,
                    isDeleted = false,
                };
                Instructor x = db.Instructor.Add(newInstructor);
                db.SaveChanges();


                return(CreatedAtRoute("DefaultApi", new { id = x.Id }, newInstructor));
            }
        }