Beispiel #1
0
        public ActionResult <AuthorDto> CreateAuthor(AuthorForCreation author)
        {
            var authorEntity = _mapper.Map <Author>(author);

            _coursesLibraryRepository.AddAuthor(authorEntity);

            _coursesLibraryRepository.Save();

            var authorToReturn = _mapper.Map <AuthorDto>(authorEntity);

            return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn));
        }
        public ActionResult <CoursesDto> CreateCourseForAuthor(Guid authorId, CourseForCreationDto course)
        {
            if (!_coursesLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var courseEntity = _mapper.Map <Course>(course);

            _coursesLibraryRepository.AddCourse(authorId, courseEntity);

            _coursesLibraryRepository.Save();

            var courseDto = _mapper.Map <CoursesDto>(courseEntity);

            return(CreatedAtRoute("GetCourseForAuthor", new { authorId = authorId, courseId = courseDto.Id }, courseDto));
        }
        public ActionResult <IEnumerable <Author> > CreateAuthors(IEnumerable <AuthorForCreation> authorsForCreation)
        {
            var authors = _mapper.Map <IEnumerable <Author> >(authorsForCreation);

            foreach (var author in authors)
            {
                _coursesLibraryRepository.AddAuthor(author);
            }

            _coursesLibraryRepository.Save();

            var authorDtos = _mapper.Map <IEnumerable <AuthorDto> >(authors);

            var idsAsString = string.Join(",", authorDtos.Select(a => a.Id));

            return(CreatedAtRoute("GetAuthorsCollection", new { ids = idsAsString }, authorDtos));
        }