Exemplo n.º 1
0
        public async Task <bool> AddCourseAsync(CourseForCreation courseForCreation)
        {
            var courseToAdd = _mapper.Map <Course>(courseForCreation);
            await _courseRepository.AddCourseAsync(courseToAdd);

            return(await _courseRepository.SaveChanges());
        }
        public async Task <ActionResult <CourseForReturn> > CreateCourseForAuthor(Guid authorId, CourseForCreation course)
        {
            if (!await _repository.AuthorExists(authorId))
            {
                return(NotFound());
            }
            var courseForAdd = _mapper.Map <Course>(course);

            _repository.AddCourse(authorId, courseForAdd);
            if (!await _repository.Save())
            {
                return(BadRequest("Error Happens when saving in Data Base"));
            }

            var courseToReturn = _mapper.Map <CourseForReturn>(courseForAdd);

            return(CreatedAtRoute("getCourse", new { authorId = authorId, courseId = courseForAdd.Id }, courseToReturn));
        }