BLL.Presupuesto.Eliminar C# (CSharp) Method

Eliminar() public method

public Eliminar ( ) : bool
return bool
        public override bool Eliminar()
        {
            ConexionDb conexion = new ConexionDb();
            bool retorno = false;
            try
            {
                retorno = conexion.Ejecutar(String.Format("Delete from Presupuestos Where PresupuestoId = {0} --", this.PresupuestoId));
            
                if (retorno)
                {
                    conexion.Ejecutar(String.Format("Delete from PresupuestoDetalle Where PresupuestoId = {0} --", this.PresupuestoId));                
                }
            }catch
            {
                retorno = false;
            }
            return retorno;
        }

Usage Example

        protected void EliminarButton_Click(object sender, EventArgs e)
        {
            Presupuesto presupuesto = new Presupuesto();
            if (presupuesto.Buscar(Convert.ToInt32(PresupuestoTextBox.Text)))
            {
                if (presupuesto.Eliminar())
                    Utilitarios.ShowToastr(this, "Registro eliminado", "Exito", "success");
                Limpiar();
            }
            else {
                EliminarRequiredFieldValidator.IsValid = false;
                Limpiar();
            }

        }