/// <summary> /// Inserts a new record into the dbo.Feedback table. /// SQL+ Routine: dbo.FeedbackInsert - Authored by Alan Hyneman /// </summary> public FeedbackInsertOutput FeedbackInsert(IFeedbackInsertInput input, bool bypassValidation = false) { if (!bypassValidation) { if (!input.IsValid()) { throw new ArgumentException("FeedbackInsertInput fails validation - use the FeedbackInsertInput.IsValid() method prior to passing the input argument to the FeedbackInsert method.", "input"); } } FeedbackInsertOutput output = new FeedbackInsertOutput(); if (sqlConnection != null) { using (SqlCommand cmd = GetFeedbackInsertCommand(sqlConnection, input)) { cmd.Transaction = sqlTransaction; FeedbackInsertCommand(cmd, output); } return(output); } for (int idx = 0; idx <= retryOptions.RetryIntervals.Count; idx++) { if (idx > 0) { System.Threading.Thread.Sleep(retryOptions.RetryIntervals[idx - 1]); } try { using (SqlConnection cnn = new SqlConnection(connectionString)) using (SqlCommand cmd = GetFeedbackInsertCommand(cnn, input)) { cnn.Open(); FeedbackInsertCommand(cmd, output); cnn.Close(); } break; } catch (SqlException sqlException) { bool throwException = true; if (retryOptions.TransientErrorNumbers.Contains(sqlException.Number)) { throwException = (idx == retryOptions.RetryIntervals.Count); if (retryOptions.Logger != null) { retryOptions.Logger.Log(sqlException); } } if (throwException) { throw; } } } return(output); }
/// <summary> /// Builds the command object for FeedbackInsert method. /// </summary> /// <param name="cnn">The connection that will execute the procedure.</param> /// <param name="input">FeedbackInsertInput instance for loading parameter values.</param> /// <returns>SqlCommand ready for execution.</returns> private SqlCommand GetFeedbackInsertCommand(SqlConnection cnn, IFeedbackInsertInput input) { SqlCommand result = new SqlCommand() { CommandType = CommandType.StoredProcedure, CommandText = "[dbo].[FeedbackInsert]", Connection = cnn }; result.Parameters.Add(new SqlParameter() { ParameterName = "@FeedbackId", Direction = ParameterDirection.Output, SqlDbType = SqlDbType.Int, Scale = 0, Precision = 10, Value = DBNull.Value }); result.Parameters.Add(new SqlParameter() { ParameterName = "@LastName", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.NVarChar, Size = 32, Value = input.LastName }); result.Parameters.Add(new SqlParameter() { ParameterName = "@FirstName", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.NVarChar, Size = 32, Value = input.FirstName }); result.Parameters.Add(new SqlParameter() { ParameterName = "@Email", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.VarChar, Size = 64, Value = input.Email }); result.Parameters.Add(new SqlParameter() { ParameterName = "@Subject", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.NVarChar, Size = 32, Value = input.Subject }); result.Parameters.Add(new SqlParameter() { ParameterName = "@Message", Direction = ParameterDirection.Input, SqlDbType = SqlDbType.NVarChar, Size = 1024, Value = input.Message }); result.Parameters.Add(new SqlParameter() { ParameterName = "@ReturnValue", Direction = ParameterDirection.ReturnValue, SqlDbType = SqlDbType.Int, Scale = 0, Precision = 10, Value = DBNull.Value }); return(result); }