Esempio n. 1
0
        /// <summary>
        /// Updates numeric options step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data</exception>
        public void UpdateNumericOptionsStep(NumericOptionsStepDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
UPDATE [dbo].[NumericOptionsStep]
SET
     [FieldId] = @fieldId
    ,[LastModifiedOn] = GETDATE()
WHERE [Id] = @id;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                using (var cmd = new SqlCommand(Sql, connection))
                {
                    cmd.Parameters.AddWithValue("@id", dto.Id);
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);

                    var rowsAffected = cmd.ExecuteNonQuery();

                    if (rowsAffected == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Inserts numeric options step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void InsertNumericOptionsStep(NumericOptionsStepDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                const string CommandText =
                    @"
INSERT INTO [dbo].[NumericOptionsStep]
  (
    [FieldId],
    [LastModifiedOn]
  )
VALUES
  (
    @p_FieldId,
    @p_LastModifiedOn
  )";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_FieldId", dto.FieldId);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", DateTime.Now);

                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            dto.Id = reader.GetInt32("Id");
                        }
                    }
                }
            }
        }