Exemplo n.º 1
0
 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));
 }
Exemplo n.º 2
0
        public ActionResult <UserDTO> Get(int id)
        {
            UserDTO userDTO = new UserDTO();
            User    user;

            try
            {
                //   _logger.LogInformation("Ejecutando Comando CreateGetUserByIdCommand(id)",id);
                GetUserByIdCommand command = CommandFactory.CreateGetUserByIdCommand(id);
                command.Execute();
                //   _logger.LogInformation("Ejecutado Comando CreateGetUserByIdCommand(id)");
                user = command.GetResult();
                //    _logger.LogDebug("Usuario del CreateGetUserByIdCommand(id)", user);
                UserMapper mapper = new UserMapper();
                userDTO = mapper.CreateDTO(user);
            }
            catch (GeneralException e)
            {
                //   _logger.LogWarning("Exception", e);
                return(BadRequest(e.Message));
            }
            catch (Exception ex)
            {
                //  _logger.LogError("BadRequest: ", ex);
                return(BadRequest("Error de servidor"));
            }
            return(Ok(userDTO));
        }
        public void CreateDTOTest()
        {
            UserMapper userMapper = MapperFactory.createUserMapper();
            var        result     = userMapper.CreateDTO(_user);

            Assert.IsInstanceOf <UserDTO>(result);
        }