Пример #1
0
        /// <summary>
        /// Inserts text 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 InsertTextOptionsStep(TextOptionsStepDto 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].[stepTextOptions]
           ([FieldId]
           ,[UseRichText]
           ,[Mask]
           ,[MaskType]
           ,[HasMaxLength]
           ,[LastUpdatedOn]
           ,[NumberOfCharacters])
     VALUES
           (@p_FieldId
           ,@p_UseRichText
           ,@p_Mask
           ,@p_MaskType
           ,@p_HasMaxLength
           ,@p_lastUpdatedOn
           ,@p_NumberOfCharacters)
    --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_UseRichText", dto.AllowRichText);
                    command.Parameters.AddWithValue("@p_Mask", dto.Mask ?? (object)DBNull.Value);
                    command.Parameters.AddWithValue("@p_MaskType", dto.MaskType ?? "Standard");
                    command.Parameters.AddWithValue("@p_HasMaxLength", dto.HasMaxLength);
                    command.Parameters.AddWithValue("@p_lastUpdatedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@p_NumberOfCharacters", dto.NumberOfCharacters);
                    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;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Updates text options.
        /// </summary>
        /// <param name="data">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicate stale data.</exception>
        public void UpdateTextOptions(TextOptionsStepDto 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 [stepTextOptions]
                    SET [UseRichText] = @p_AllowRichText,
                        [Mask] = @p_Mask,
                        [MaskType] = @p_MaskType,
                        [HasMaxLength] = @p_HasMaxLength,
                        [LastUpdatedOn] = @p_lastUpdatedOn,
                        [NumberOfCharacters] = @p_NumberOfCharacters
                    WHERE id = @p_id";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", data.Id);
                    command.Parameters.AddWithValue("@p_AllowRichText", data.AllowRichText);
                    command.Parameters.AddWithValue("@p_Mask", data.Mask ?? string.Empty);
                    command.Parameters.AddWithValue("@p_MaskType", data.MaskType);
                    command.Parameters.AddWithValue("@p_HasMaxLength", data.HasMaxLength);
                    command.Parameters.AddWithValue("@p_lastUpdatedOn", DateTime.Now);
                    command.Parameters.AddWithValue("@p_NumberOfCharacters", data.NumberOfCharacters);

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