コード例 #1
0
        public async Task <ActionResult <AuthorDto> > CreateAuthor(AuthorForCreationDto authorForCreationDto)
        {
            var authorEntity = _mapper.Map <Author>(authorForCreationDto);

            _courseLibraryRepository.AddAuthor(authorEntity);
            await _courseLibraryRepository.SaveAsync();

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

            return(CreatedAtRoute("GetAuthor", new { authorId = authorToReturn.Id }, authorToReturn));
        }
コード例 #2
0
        public async Task <IActionResult> CreateAuthorCollection(IEnumerable <AuthorCreationDto> authors)
        {
            if (!authors.Any())
            {
                return(NotFound());
            }

            var authorsEntity = _mapper.Map <IEnumerable <Author> >(authors);

            _courseLibraryRepository.AddAuthorRange(authorsEntity);
            await _courseLibraryRepository.SaveAsync();

            var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorsEntity);

            var idsToReturn = string.Join(",", authorCollectionToReturn.Select(c => c.Id));

            return(CreatedAtRoute(
                       "GetAuthorCollection",
                       new
            {
                authorIds = idsToReturn
                            //authorIds = authorsEntity.Select(c => c.Id)
                            //authorIds = from author in authorsEntity select author.Id
            },
                       authorCollectionToReturn));
        }
コード例 #3
0
        public async Task <ActionResult <CourseDto> > CreatecourseForAction(Guid authorId, CourseForCreationDto courseForCreation)
        {
            if (!_courseLibraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

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

            _courseLibraryRepository.AddCourse(authorId, courseEntity);
            await _courseLibraryRepository.SaveAsync();

            var courseToReturn = _mapper.Map <CourseDto>(courseEntity);

            return(CreatedAtRoute("GetCourseForAuthor",
                                  new { authorId = authorId, courseId = courseToReturn.Id },
                                  courseToReturn));
        }
コード例 #4
0
        public async Task <ActionResult <AuthorDto> > CreateAuthor(AuthorCreationDto authorCreation)
        {
            //if (author == null) // This control provide us from ApiController attribute.
            //{
            //    return BadRequest();
            //}

            var authorEntity = _mapper.Map <Author>(authorCreation);

            _courseLibraryRepository.AddAuthor(authorEntity);
            await _courseLibraryRepository.SaveAsync();

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

            return(CreatedAtRoute("GetAuthor",
                                  new { authorId = authorToReturn.Id },
                                  authorToReturn));
        }
コード例 #5
0
        public async Task <ActionResult <IEnumerable <AuthorDto> > > CreateAuthorCollection(IEnumerable <AuthorForCreationDto> authorCollection)
        {
            var authorEntities = _mapper.Map <IEnumerable <Author> >(authorCollection);

            foreach (var author in authorEntities)
            {
                _courseLibraryRepository.AddAuthor(author);
            }
            await _courseLibraryRepository.SaveAsync();

            var authorCollectionToReturn = _mapper.Map <IEnumerable <AuthorDto> >(authorEntities);
            var idsAsString = string.Join(",", authorCollectionToReturn.Select(a => a.Id));

            return(CreatedAtRoute("GetAuthorCollection",
                                  new { ids = idsAsString },
                                  authorCollectionToReturn));
        }