Beispiel #1
0
        public IActionResult CreateCourse(int schoolId, [FromBody] CourseDTO courseDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int    maxCourseId = _schoolRepository.GetSchool(schoolId).CoursesList.Max(c => c.Id);
            Course course      = new Course()
            {
                Id              = ++maxCourseId,
                Name            = courseDTO.Name,
                Subject         = courseDTO.Subject,
                Description     = courseDTO.Description,
                CourseMaterials = courseDTO.CourseMaterials
            };

            _schoolRepository.AddCourse(course, schoolId);
            return(CreatedAtRoute("GetCourse", new { schoolId, courseId = course.Id }, course));
        }
        public IActionResult CreateCourse(int schoolId, [FromBody] CourseDTO courseDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            int subjectId = courseDTO.SubjectId;
            ICollection <Subject> schoolSubjects = _schoolRepository.GetAllSubjects(schoolId);
            Subject subject = schoolSubjects.FirstOrDefault(sbj => sbj.Id == subjectId);
            Course  course  = new Course()
            {
                Name        = courseDTO.Name,
                Subject     = subject,
                Description = courseDTO.Description,
                Documents   = courseDTO.Documents
            };

            _schoolRepository.AddCourse(course, schoolId);
            return(CreatedAtRoute("GetCourse", new { schoolId, courseId = course.Id }, course));
        }