예제 #1
0
        public ActionResult <AuthorDto> CreateAuthor([FromBody] AuthorAddDto author)
        {
            var authorEntity  = mapper.Map <Author>(author);
            var createdAuthor = authorRepository.CreateAuthor(authorEntity);
            var result        = mapper.Map <AuthorDto>(createdAuthor);

            return(CreatedAtRoute(nameof(GetAuthor), new { id = result.Id }, result));
        }
예제 #2
0
        public ActionResult <AuthorReadDto> AddAuthor(AuthorAddDto theAuthor)
        {
            var authorContent = _mapper.Map <Author>(theAuthor);

            _authorRepo.AddAuthor(authorContent);

            var authorOutDto = _mapper.Map <AuthorReadDto>(authorContent);

            return(CreatedAtRoute(nameof(GetAuthorById), new { Id = authorOutDto.Id }, authorOutDto));
        }
예제 #3
0
        public async Task <IActionResult> Register(AuthorAddDto authorAddDto)
        {
            if (!ModelState.IsValid)
            {
                return(View(authorAddDto));
            }

            await _authorService.AddAsync(authorAddDto);

            return(Redirect("/"));
        }
예제 #4
0
        public ActionResult UpdateAuthon(int id, AuthorAddDto authorAddDto)
        {
            var theAuthor = _authorRepo.GetAuthorById(id);

            if (theAuthor == null)
            {
                return(NotFound());
            }
            _mapper.Map(authorAddDto, theAuthor); // this syntax allows to update like(source, target)
            _authorRepo.SaveChanges();

            return(NoContent());
        }
예제 #5
0
        public async Task <IActionResult> Add(AuthorAddDto authorDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var author       = _mapper.Map <Author>(authorDto);
            var authorResult = await _authorService.Add(author);

            if (authorResult == null)
            {
                return(BadRequest());
            }

            return(Ok(_mapper.Map <AuthorResultDto>(authorResult)));
        }