Skip to content

Instantly share code, notes, and snippets.

@mdcarmo
Created March 21, 2018 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdcarmo/be6b4426e24d192b1d4a239aa4369943 to your computer and use it in GitHub Desktop.
Save mdcarmo/be6b4426e24d192b1d4a239aa4369943 to your computer and use it in GitHub Desktop.
public class AlgumController
{
public IActionResult GetAll()
{
//recupero todas as entidades
var users = _service.GetAll();
//transformo uma lista de entidades em uma lista de dtos
var userDtos = _mapper.Map<IList<UserDto>>(users);
//retorna a lista de dtos
return Ok(userDtos);
}
public IActionResult GetById(int id)
{
//recupero um usuário pelo ID
var user = _service.GetById(id);
if (user != null)
{
//transformo uma entidade em DTO
var userDto = _mapper.Map<UserDto>(user);
//retorna o DTO
return Ok(userDto);
}
else
return NotFound();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment