Exemplo n.º 1
0
        /// <summary>
        /// Inserts a new record into the dbo.Paciente table.
        /// SQL+ Routine: dbo.PacienteInsert - Authored by IStrficek
        /// </summary>
        public PacienteInsertOutput PacienteInsert(IPacienteInsertInput input)
        {
            if (!input.IsValid())
            {
                throw new ArgumentException("PacienteInsertInput fails validation - use the PacienteInsertInput.IsValid() method prior to passing the input argument to the PacienteInsert method.", "input");
            }

            PacienteInsertOutput output = new PacienteInsertOutput();

            if (sqlConnection != null)
            {
                using (SqlCommand cmd = GetPacienteInsertCommand(sqlConnection, input))
                {
                    cmd.Transaction = sqlTransaction;
                    PacienteInsertCommand(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 = GetPacienteInsertCommand(cnn, input))
                        {
                            cnn.Open();
                            PacienteInsertCommand(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);
        }
Exemplo n.º 2
0
 private void SetPacienteInsertCommandOutputs(SqlCommand cmd, PacienteInsertOutput output)
 {
     if (cmd.Parameters[0].Value != DBNull.Value)
     {
         output.IdPaciente = (int?)cmd.Parameters[0].Value;
     }
     if (cmd.Parameters[9].Value != DBNull.Value)
     {
         output.ReturnValue = (PacienteInsertOutput.Returns)cmd.Parameters[9].Value;
     }
 }
Exemplo n.º 3
0
        private void PacienteInsertCommand(SqlCommand cmd, PacienteInsertOutput output)
        {
            cmd.ExecuteNonQuery();

            SetPacienteInsertCommandOutputs(cmd, output);
        }