示例#1
0
        public IHttpActionResult CreateCourse(CourseCreator courseCreator)
        {
            coursesService         = new CoursesService();
            subjectsService        = new SubjectsService();
            teachersService        = new TeachersService();
            subjectToExposeService = new SubjectToExposeService();
            courseToExposeService  = new CourseToExposeService();

            if (courseCreator == null)
            {
                return(BadRequest());
            }

            bool exists = false;

            exists = coursesService.CheckIfCourseAlreadyExists(courseCreator.Title);

            if (exists)
            {
                return(BadRequest());
            }

            List <CourseSubject> courseSubjects = coursesService.CreateCourse(courseCreator);

            List <SubjectToExpose> subjectsToExpose = new List <SubjectToExpose>();

            foreach (CourseSubject courseSubject in courseSubjects)
            {
                Subject subject = new Subject();
                subject = subjectsService.Find(courseSubject.SubjectId);

                if (subject == null)
                {
                    return(BadRequest());
                }

                if (subject.ID == 0)
                {
                    return(BadRequest());
                }

                Teacher teacher = new Teacher();

                teacher = teachersService.GetTeacherNameByID(subject.TeacherId);

                if (teacher == null)
                {
                    return(BadRequest());
                }

                SubjectToExpose subjectToExpose = subjectToExposeService.TrimSubject(subject);

                subjectsToExpose.Add(subjectToExpose);
            }

            CourseToExpose course = courseToExposeService
                                    .TrimSubject(courseSubjects, courseCreator, subjectsToExpose);

            return(Created(new Uri(Request.RequestUri + "/" + course.Id), course));
        }
示例#2
0
 public async Task <ActionResult <Course> > CreateCourse(Course course)
 {
     return(await _coursesService.CreateCourse(course));
 }