Esempio 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));
 }
Esempio n. 2
0
        public void AddUserTest()
        {
            PostUserCommand postUserCommand = new PostUserCommand(_user);

            postUserCommand.Execute();
            var user = postUserCommand.GetResult();

            _insertedUsers.Add(user.Id);
            Assert.True(user.Id > 0);
        }
Esempio n. 3
0
        public void DeleteUserByIdTest()
        {
            PostUserCommand postUserCommand = new PostUserCommand(_user);

            postUserCommand.Execute();
            var user = postUserCommand.GetResult();
            DeleteUserByIdCommand deleteUserByIdCommand = new DeleteUserByIdCommand(user.Id);

            deleteUserByIdCommand.Execute();
            var id = deleteUserByIdCommand.GetResult();

            Assert.AreEqual(id, user.Id);
        }