Ejemplo n.º 1
0
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        //USUARIO
        string US_nombre     = txtNombre.Text;
        string US_apellido   = txtApellido.Text;
        string US_telefono   = txtTelefono.Text;
        string US_email      = txtEmail.Text;
        string US_contraseña = txtContrasena.Text;

        if (string.IsNullOrEmpty(US_nombre))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El campo Nombre no debe estar vacío')", true);
            return;
        }

        if (string.IsNullOrEmpty(US_apellido))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El campo Apellido no debe estar vacío')", true);
            return;
        }

        if (string.IsNullOrEmpty(US_telefono))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El campo Teléfono no debe estar vacío')", true);
            return;
        }

        if (string.IsNullOrEmpty(US_email))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El campo Email no debe estar vacío')", true);
            return;
        }

        if (string.IsNullOrEmpty(US_contraseña))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El campo Contraseña no debe estar vacío')", true);
            return;
        }

        if (US_contraseña.Length < 6)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('La contraseña debe almacenar 6 caracteres como mínimo')", true);
            return;
        }
        else if (US_contraseña.Length > 50)
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('La contraseña debe almacenar 50 caracteres como máximo')", true);
            return;
        }

        if (UsuarioBRL.GetUsuarioByEmail(US_email) == null)
        {
            //REGISTRANDO USUARIO

            Usuario obj = new Usuario()
            {
                Nombre     = US_nombre,
                Apellido   = US_apellido,
                Telefono   = US_telefono,
                Correo     = US_email,
                Contrasena = US_contraseña,
            };

            int idUsuario = UsuarioBRL.InsertarUsuario(obj);

            Enviar(US_email);
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El Usuario se ha registrado Exitosamente!!!')", true);

            Response.Redirect("~/Home.aspx");
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('El correo electrónico indicado ya está registrado')", true);
            return;
        }
    }