public void Add(Student st, POCOStudent pocoStudent) { if (pocoStudent.CourseId != null) { foreach (int id in pocoStudent.CourseId) { Student_Course sc = new Student_Course() { course_id = id, student_id = st.id }; db.Student_Course.Add(sc); db.SaveChanges(); } } }
public IHttpActionResult PostStudent(POCOStudent pocoStudent) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Student student = new Student() { name = pocoStudent.Name, phone = pocoStudent.Phone, mail = pocoStudent.Mail, birthdate = pocoStudent.Birthdate, }; var st = db.Students.Add(student); db.SaveChanges(); studentManager.Add(st, pocoStudent); return(CreatedAtRoute("DefaultApi", new { id = st.id }, st)); }