public bool InsertNewPasswordResetRequestAndSetAccountDeleted(TestSprocGenerator.Data.SingleTable.Dto.Account account, string passwordResetCode) { bool successful = true; BaseDatabase baseDatabase = new BaseDatabase(); SqlTransaction transaction = null; try { using (_smoSettings[CONNECTION_STRING_NAME].Connection) { baseDatabase.OpenConnectionIfClosed(_smoSettings[CONNECTION_STRING_NAME].Connection); //this caused errors cause we were beginning the transaction at the whole server caused big problems //transaction = _smoSettings[CONNECTION_STRING_NAME].Connection.BeginTransaction(); transaction = null; bool passwordResetRequestInsertOK = InsertPasswordResetRequest(account, passwordResetCode, _smoSettings[CONNECTION_STRING_NAME].Connection, ref transaction, BaseDatabase.TransactionBehavior.Begin); if (!passwordResetRequestInsertOK) { successful = false; throw new ApplicationException("Password Reset Request Insert Failed"); } bool updateAccountToDeletedOK = UpdateAccount(account, _smoSettings[CONNECTION_STRING_NAME].Connection, ref transaction, BaseDatabase.TransactionBehavior.Enlist); if (!updateAccountToDeletedOK) { successful = false; throw new ApplicationException("Update to Account Set to Deleted Failed"); } if (successful == true) { baseDatabase.CommitTransaction(ref transaction); } else { throw new ApplicationException("Insert new Password Reset Request Method failed in AccountDataAccess Failed, transaction has been rolled back"); } } } catch (Exception ex) { baseDatabase.RollbackTransaction(ref transaction); throw new ApplicationException("Insert new Password Reset Request Method in RegistrationDataAccess Failed", ex); } return(successful); }
/// <summary> /// save the customer and its dependent objects wrapped in one SqlTransaction /// </summary> /// <param name="customer"></param> internal void Save(Customer customer) { BaseDatabase _baseDatabase = new BaseDatabase(); SqlTransaction transaction = null; using (SqlConnection sqlConnection = new SqlConnection(_databaseSmoObjectsAndSettings.ConnectionString)) { // begin and the rest are set to enlist BaseDatabase.TransactionBehavior transactionBehavior = BaseDatabase.TransactionBehavior.Begin; try { SavePerson(customer, sqlConnection, ref transaction, transactionBehavior); SaveAddress(customer, sqlConnection, ref transaction, transactionBehavior); SaveContact(customer, sqlConnection, ref transaction, transactionBehavior); _baseDatabase.CommitTransaction(ref transaction); ResetModifiedState(customer); } catch (BeginTransactionException beginTrans) { _baseDatabase.RollbackTransaction(ref transaction); //this is a developer specific type of exception throw new ApplicationException(beginTrans.Message); } catch (Exception ex) { //ensure transaction is rolled back _baseDatabase.RollbackTransaction(ref transaction); //bubble it back up to consumer for graceful recovery throw ex; } } }