Created
March 21, 2018 14:32
-
-
Save mdcarmo/be6b4426e24d192b1d4a239aa4369943 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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