Ejemplo n.º 1
0
        /// <summary>
        /// Inserts auto number step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void InsertAutoNumberStep(AutoNumberStepDto 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].[AutoNumberFieldStep]
           ([Expression], LastUpdatedOn, FieldId, Reset)
     VALUES
           (@p_Expression, @p_LastModifiedOn, @p_FieldId, @p_Reset)
    SET @p_id = SCOPE_IDENTITY()";

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_FieldId", dto.FieldId);
                    command.Parameters.AddWithValue("@p_Expression", dto.Expression);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@p_Reset", dto.AutoNumberReset);
                    var idParam = new SqlParameter("@p_id", SqlDbType.Int, 0, "Id") { Direction = ParameterDirection.Output };
                    command.Parameters.Add(idParam);

                    command.ExecuteNonQuery();

                    dto.Id = (int)idParam.Value;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates auto number step.
        /// </summary>
        /// <param name="buildDto">The build DTO.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void UpdateAutoNumberStep(AutoNumberStepDto buildDto)
        {
            if (buildDto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "buildDto"));
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var connection = ctx.Connection;

                const string CommandText =
                    @"
                    UPDATE [dbo].[AutoNumberFieldStep]
                    SET [Expression] = @p_Expression, [LastUpdatedOn] = @p_LastModifiedOn, [Reset] = @p_Reset
                    WHERE id = @p_id";

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_id", buildDto.Id);
                    command.Parameters.AddWithValue("@p_Expression", buildDto.Expression);
                    command.Parameters.AddWithValue("@p_LastModifiedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@p_Reset", buildDto.AutoNumberReset);

                    command.ExecuteNonQuery();
                }
            }
        }