Пример #1
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();
                }
            }
        }
Пример #2
0
        public POCOCourse GetCourse(int id)
        {
            POCOCourse course = db.Courses.Select(a => new POCOCourse {
                Name = a.name, Code = a.code, NoOfHours = a.noOfHours, Id = a.id, InstructorsName = a.Instructor_Course.Where(b => b.course_id == a.id).Select(b => b.Instructor.name).ToList(), StudentsName = a.Student_Course.Where(b => b.course_id == a.id).Select(b => b.Student.name).ToList()
            }).FirstOrDefault(a => a.Id == id);

            return(course);
        }
Пример #3
0
        public IHttpActionResult PostCourse(POCOCourse pocoCourse)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Course course = new Course()
            {
                name      = pocoCourse.Name,
                code      = pocoCourse.Code,
                noOfHours = pocoCourse.NoOfHours,
            };
            var c = db.Courses.Add(course);

            db.SaveChanges();
            courseManager.Add(c, pocoCourse);
            return(CreatedAtRoute("DefaultApi", new { id = c.id }, c));
        }