public IActionResult CreateCourseSection([FromBody] CourseSectionForCreationDto coursesection) { if (coursesection == null) { _logger.LogError("CourseManage ForCreationDto object sent from client is null."); return(BadRequest("CourseManage ForCreationDto object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the CourseSectionForCreationDto object"); return(UnprocessableEntity(ModelState)); } var coursesectionEntity = _mapper.Map <CourseSection>(coursesection); _repository.CourseSection.CreateCourseSection(coursesectionEntity); _repository.Save(); var userToReturn = _mapper.Map <CourseSectionDto>(coursesectionEntity); return(CreatedAtRoute("CourseSectionByID", new { id = userToReturn.Id }, userToReturn)); }
public async Task <IActionResult> CreateCourseSectionForCourse(Guid courseId, [FromBody] CourseSectionForCreationDto coursesection) { if (coursesection == null) { _logger.LogError("CourseSectionForCreationDto object sent from client is null."); return(BadRequest("CourseSectionForCreationDto object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid model state for the CourseSectionForCreationDto object"); return(UnprocessableEntity(ModelState)); } var course = await _repository.CourseMgt.GetCourseAsync(courseId, trackChanges : false); if (course == null) { _logger.LogInfo($"Course with id: {courseId} doesn't exist in the database."); return(NotFound()); } var coursesectionEntity = _mapper.Map <CourseSectionMgt>(coursesection); _repository.CourseSectionMgt.CreateCourseSectionForCourse(courseId, coursesectionEntity); await _repository.SaveAsync(); var coursesectionToReturn = _mapper.Map <CourseSectionDto>(coursesectionEntity); return(CreatedAtRoute("GetCoursesectionForCourse", new { courseId, id = coursesectionToReturn.Id }, coursesectionToReturn)); }