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)); }
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)); }
public async Task <IActionResult> Register(AuthorAddDto authorAddDto) { if (!ModelState.IsValid) { return(View(authorAddDto)); } await _authorService.AddAsync(authorAddDto); return(Redirect("/")); }
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()); }
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))); }