public EMunicipios Municipios_Update(EMunicipios item, ref ETransactionResult _transResult) { EMunicipios itemUpdated = null; _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("UpdateTransaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "SP_Municipios_Update"; sqlCmd.Parameters.AddWithValue("@Id", item.Id); sqlCmd.Parameters.AddWithValue("@IdEstado", item.IdEstado); sqlCmd.Parameters.AddWithValue("@descripcion", item.descripcion); using (var reader = sqlCmd.ExecuteReader()) { while (reader.Read()) { itemUpdated = new EMunicipios(); itemUpdated.Id = (int)reader["Id"]; itemUpdated.IdEstado = (int)reader["IdEstado"]; itemUpdated.descripcion = reader["descripcion"] == DBNull.Value ? null : (string)reader["descripcion"]; } } transaction.Commit(); _transResult.message = "OK"; _transResult.result = 1; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } return(itemUpdated); }
public List <EMunicipios> Municipios_GetAll(ref ETransactionResult _transResult) { var list = new List <EMunicipios>(); _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("SelectAllTranstaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "SP_Municipios_SelectAll"; using (var reader = sqlCmd.ExecuteReader()) while (reader.Read()) { var item = new EMunicipios(); item.Id = (int)reader["Id"]; item.IdEstado = (int)reader["IdEstado"]; item.descripcion = reader["descripcion"] == DBNull.Value ? null : (string)reader["descripcion"]; list.Add(item); } transaction.Commit(); _transResult.message = "OK"; _transResult.result = 0; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } return(list); }
public void Municipios_Delete(EMunicipios item, ref ETransactionResult _transResult) { _transResult = new ETransactionResult(); SqlTransaction transaction = null; try { using (SqlConnection sqlCon = new SqlConnection(conn)) { sqlCon.Open(); using (SqlCommand sqlCmd = new SqlCommand()) { transaction = sqlCon.BeginTransaction("DeleteTransaction"); sqlCmd.Transaction = transaction; sqlCmd.Connection = sqlCon; sqlCmd.CommandType = CommandType.StoredProcedure; sqlCmd.CommandText = "SP_Municipios_Delete"; sqlCmd.Parameters.AddWithValue("@Id", item.Id); sqlCmd.Parameters.AddWithValue("@IdEstado", item.IdEstado); sqlCmd.ExecuteNonQuery(); transaction.Commit(); _transResult.message = "OK"; _transResult.result = 0; } } } catch (Exception ex) { _transResult.message = ex.Message; _transResult.result = 1; try { transaction.Rollback(); } catch (Exception rollBackEx) { _transResult.rollbackMessage = rollBackEx.Message; _transResult.result = 1; } } }