Пример #1
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();
                }
            }
        }
        public IHttpActionResult PostInstructor(POCOInstructor pocoInstructor)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Instructor instructor = new Instructor()
            {
                name       = pocoInstructor.Name,
                phone      = pocoInstructor.Phone,
                department = pocoInstructor.Department,
                mail       = pocoInstructor.Mail,
            };
            var inst = db.Instructors.Add(instructor);

            db.SaveChanges();
            instructorManager.Add(inst, pocoInstructor);

            return(CreatedAtRoute("DefaultApi", new { id = inst.id }, inst));
        }