public override bool Update(Cliente instance, object otro, out Exception exError) { SqlTransaction trans; SqlCommand command; Direccion direccion = (Direccion)otro; exError = null; try { if (this.Connection.State != ConnectionState.Open) { this.Connection.Open(); } using (trans = ((SqlConnection)this.Connection).BeginTransaction()) { try { command = new SqlCommand("UPDATE " + Table + " SET " + SqlHelper.getUpdate(instance.getAtributeMList()) + " WHERE id_cliente=" + instance.id_cliente, (SqlConnection)this.Connection, trans); command.CommandType = System.Data.CommandType.Text; foreach (String value in instance.getAtributeMList()) { command.Parameters.AddWithValue("@" + value, instance.getMethodString(value)); } command.ExecuteNonQuery(); command.CommandText = "UPDATE " + DTable + " SET " + SqlHelper.getUpdate(direccion.getAtributeMList()) + " WHERE id_domicilio=" + direccion.id_domicilio; foreach (String value in direccion.getAtributeMList()) { command.Parameters.AddWithValue("@" + value, direccion.getMethodString(value)); } command.ExecuteNonQuery(); trans.Commit(); } catch (Exception ex2) { try { trans.Rollback(); } catch { exError = ex2; } } } } catch (InvalidOperationException invalid) { exError = invalid; } return(true); }
public override Int32 Create(Cliente instance, object otro, out Exception exError) { Int32 modified = -1; SqlTransaction trans; SqlCommand command; Direccion direccion = (Direccion)otro; exError = null; try { if (this.Connection.State != ConnectionState.Open) { this.Connection.Open(); } using (trans = ((SqlConnection)this.Connection).BeginTransaction()) { try { command = new SqlCommand("INSERT INTO " + DTable + " (" + SqlHelper.getColumns(direccion.getAtributeMList()) + ")" + " output INSERTED.id_domicilio VALUES(" + SqlHelper.getValues(direccion.getAtributeMList()) + ")", (SqlConnection)this.Connection, trans); command.CommandType = System.Data.CommandType.Text; foreach (String value in direccion.getAtributeMList()) { command.Parameters.AddWithValue("@" + value, direccion.getMethodString(value)); } modified = (Int32)command.ExecuteScalar(); instance.id_domicilio = modified; command.CommandText = "INSERT INTO " + Table + " (" + SqlHelper.getColumns(instance.getAtributeMList()) + ")" + " output INSERTED.id_cliente VALUES(" + SqlHelper.getValues(instance.getAtributeMList()) + ")"; foreach (String value in instance.getAtributeMList()) { command.Parameters.AddWithValue("@" + value, instance.getMethodString(value)); } modified = (Int32)command.ExecuteScalar(); trans.Commit(); } catch (Exception ex2) { try { exError = ex2; trans.Rollback(); } catch { exError = ex2; } } } } catch (InvalidOperationException invalid) { exError = invalid; } return(modified); }