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
        // TODO: Retornar el usuario actualizado
        public ActionResult <int> Put(int id, [FromBody] User user)
        {
            int user_id;

            try
            {
                // _logger.LogInformation("Ejecutando Comando UpdateUserCommand(user,id)", user,id);
                UpdateUserCommand updateUserCommand = new UpdateUserCommand(user, id);
                updateUserCommand.Execute();
                //  _logger.LogInformation("Ejecutado Comando UpdateUserCommand(user,id)", user, id);
                user_id = updateUserCommand.GetResult();
                //  _logger.LogInformation("Ejecutando Comando DeleteUser_RoleCommand(id)", id);
                DeleteUser_RoleCommand deleteUser_RoleCommand = new DeleteUser_RoleCommand(id);
                deleteUser_RoleCommand.Execute();
                //  _logger.LogInformation("Ejecutado Comando DeleteUser_RoleCommand(id)", id);
                PostUser_RoleCommand postUser_RoleCommand;
                foreach (var role in user.Roles)
                {
                    //  _logger.LogInformation("Ejecutando Comando PostUser_RoleCommand(id,role)", id,role);
                    postUser_RoleCommand = new PostUser_RoleCommand(id, role);
                    postUser_RoleCommand.Execute();
                    //  _logger.LogInformation("Ejecutado Comando PostUser_RoleCommand(id,role)", id, role);
                }

                return(Ok(user_id));
            }
            catch (GeneralException e)
            {
                // _logger.LogWarning("Exception", e);
                return(BadRequest(e.Message));
            }
            catch (Exception ex)
            {
                // _logger.LogError("BadRequest: ", ex);
                return(BadRequest("Error actualizando al usuario"));
            }
        }