public ActionResult <UserDTO> Post([FromBody] UserDTO user) { try { UserMapper mapper = new UserMapper(); User entity = mapper.CreateEntity(user); // _logger.LogInformation("Ejecutando Comando PostUserCommand(entity)", entity); PostUserCommand command = new PostUserCommand(entity); command.Execute(); // _logger.LogInformation("Ejecutado Comando PostUserCommand(entity)"); foreach (var role in user.Roles) { // _logger.LogInformation("Ejecutando Comando PostUser_RoleCommand(entity.Id,role)", entity,role); PostUser_RoleCommand postRoleCommand = new PostUser_RoleCommand(entity.Id, role); postRoleCommand.Execute(); // _logger.LogInformation("Ejecutado Comando PostUser_RoleCommand(entity.Id,role)",entity, role); } user = mapper.CreateDTO((User)command.GetResult()); } catch (GeneralException e) { // _logger.LogWarning("Exception", e); return(BadRequest(e.Message)); } catch (Exception ex) { // _logger.LogError("BadRequest: ", ex); return(BadRequest("Error agregando al usuario")); } return(Ok(user)); }
public void CreateEntityTest() { UserMapper userMapper = MapperFactory.createUserMapper(); UserDTO userDTO = DTOFactory.CreateUserDTO(_user.Id, _user.DocumentId, _user.Email, _user.Lastname, _user.Name, _user.Password, _user.Roles); var result = userMapper.CreateEntity(userDTO); Assert.IsInstanceOf <User>(result); }