public IHttpActionResult AddNewCollege([FromBody] IESCollege college) { try { var context = new xPenEntities(); context.IESColleges.Add(college); context.SaveChanges(); return(Ok()); } catch (Exception ex) { return(InternalServerError()); } }
public IHttpActionResult AddNewCollegeWithStream([FromBody] College_Courses college_course) { try { var context = new xPenEntities(); using (var dbContextTransaction = context.Database.BeginTransaction()) { IESCollege college = new IESCollege { CollegeName = college_course.CollegeName, UniversityID = college_course.UnivID }; context.IESColleges.Add(college); context.SaveChanges(); List <IESStream> courses = college_course.Streams; foreach (IESStream i in courses) { context.IESCourses.Add( new IESCourse { CollegeID = college.CollegeID, StreamID = i.StreamID } ); } context.SaveChanges(); dbContextTransaction.Commit(); } return(Ok()); } catch (Exception ex) { return(InternalServerError()); } }