Exemple #1
0
        /// <summary>
        /// Inserts label 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 InsertLabelOptionsStep(LabelOptionsStepDto 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].[stepLabelOptions]
        ( [FieldId] ,
          [LabelText] ,
          [HideFieldName]
        )
VALUES  ( @p_FieldId ,
          @p_LabelText ,
          @p_HideFieldName
        )

    --DECLARE @Identity AS INT
SET @p_id = SCOPE_IDENTITY()";

                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_FieldId", dto.FieldId);
                    command.Parameters.AddWithValue("@p_LabelText", dto.LabelText);
                    command.Parameters.AddWithValue("@p_HideFieldName", dto.HideFieldName);
                    var idParam = new SqlParameter("@p_id", SqlDbType.Int, 0, "Id")
                                      {
                                          Direction =
                                              ParameterDirection.Output
                                      };
                    command.Parameters.Add(idParam);

                    var rowsAffetcted = command.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }

                    dto.Id = (int)idParam.Value;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates label options.
        /// </summary>
        /// <param name="data">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 UpdateLabelOptions(LabelOptionsStepDto data)
        {
            if (data == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "data"));

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

                const string CommandText =
                    @"
UPDATE  [stepLabelOptions]
SET     [LabelText] = @p_LabelText ,
        [HideFieldName] = @p_HideFieldName
WHERE   id = @p_id";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", data.Id);
                    command.Parameters.AddWithValue("@p_LabelText", data.LabelText);
                    command.Parameters.AddWithValue("@p_HideFieldName", data.HideFieldName);

                    var rowsAffetcted = command.ExecuteNonQuery();
                    if (rowsAffetcted == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }