예제 #1
0
        /// <summary>
        /// Inserts checkbox options step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        public void InsertCheckboxOptionsStep(CheckboxOptionsStepDto 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].[stepCheckboxOptions]
    ([IsSwitchToggle]
    ,[DefaultValue]
    ,[MainLabel]
    ,[UndefinedLabel]
    ,[TrueLabel]
    ,[FalseLabel]
    ,[FieldId])
VALUES
    (@p_IsSwitchToggle
    ,@p_DefaultValue
    ,@p_MainLabel
    ,@p_UndefinedLabel
    ,@p_TrueLabel
    ,@p_FalseLabel
    ,@p_FieldId)

SELECT CAST(SCOPE_IDENTITY() AS INT)
";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_IsSwitchToggle", dto.IsSwitchToggle);
                    command.Parameters.AddWithValue("@p_FieldId", dto.FieldId);
                    command.Parameters.AddWithValue("@p_MainLabel", dto.MainLabel ?? string.Empty);
                    command.Parameters.AddWithValue("@p_UndefinedLabel", dto.UndefinedLabel);
                    command.Parameters.AddWithValue("@p_TrueLabel", dto.TrueLabel);
                    command.Parameters.AddWithValue("@p_FalseLabel", dto.FalseLabel);

                    if (dto.DefaultValue == null)
                    {
                        command.Parameters.AddWithValue("@p_DefaultValue", DBNull.Value);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@p_DefaultValue", dto.DefaultValue);
                    }

                    dto.Id = (int)command.ExecuteScalar();
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Updates checkbox options step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void UpdateCheckboxOptionsStep(CheckboxOptionsStepDto 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 =
                    @"
UPDATE [dbo].[stepCheckboxOptions]
SET
     [IsSwitchToggle]=@p_IsSwitchToggle
    ,[DefaultValue]  =@p_DefaultValue
    ,[MainLabel]     =@p_MainLabel
    ,[UndefinedLabel]=@p_UndefinedLabel
    ,[TrueLabel]     =@p_TrueLabel
    ,[FalseLabel]    =@p_FalseLabel
 WHERE [Id]=@p_Id
";
                using (var command = new SqlCommand(CommandText, connection))
                {
                    command.Parameters.AddWithValue("@p_Id", dto.Id);
                    command.Parameters.AddWithValue("@p_IsSwitchToggle", dto.IsSwitchToggle);
                    command.Parameters.AddWithValue("@p_MainLabel", AdoHelper.NullCheck(dto.MainLabel));
                    command.Parameters.AddWithValue("@p_UndefinedLabel", AdoHelper.NullCheck(dto.UndefinedLabel));
                    command.Parameters.AddWithValue("@p_TrueLabel", AdoHelper.NullCheck(dto.TrueLabel));
                    command.Parameters.AddWithValue("@p_FalseLabel", AdoHelper.NullCheck(dto.FalseLabel));

                    if (dto.DefaultValue == null)
                    {
                        command.Parameters.AddWithValue("@p_DefaultValue", DBNull.Value);
                    }
                    else
                    {
                        command.Parameters.AddWithValue("@p_DefaultValue", dto.DefaultValue);
                    }

                    command.ExecuteScalar();
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Fetches checkbox options.
        /// </summary>
        /// <param name="processName">The process name.</param>
        /// <param name="fieldName">The field name.</param>
        /// <param name="isPublishedCopy">The is published copy.</param>
        /// <returns>The <see cref="CheckboxOptionsStepDto" />.</returns>
        public CheckboxOptionsStepDto FetchCheckboxOptions(string processName, string fieldName, bool isPublishedCopy = false)
        {
            const string CmdText =
                @"
DECLARE @fieldId AS INT

SELECT @fieldId = f.Id
FROM
    [dbo].[Processes] p
    INNER JOIN [dbo].[Sections] s ON s.ProcessId = p.Id
    INNER JOIN [dbo].[Fields] f ON f.SectionId = s.Id
WHERE p.[SystemName] = @processName AND p.IsRemoved = 0 AND p.IsPublishedCopy = @isPublishedCopy AND f.SystemName = @fieldName;

EXEC [dbo].[GetCheckboxOptionsStep] @FieldId = @fieldId;
";

            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            using (var cmd = new SqlCommand(CmdText, ctx.Connection))
            {
                cmd.Parameters.AddWithValue("@processName", processName);
                cmd.Parameters.AddWithValue("@fieldName", fieldName);
                cmd.Parameters.AddWithValue("@isPublishedCopy", isPublishedCopy);

                using (var reader = new SafeDataReader(cmd.ExecuteReader()))
                {
                    if (reader.Read())
                    {
                        var dto = new CheckboxOptionsStepDto
                                      {
                                          Id = reader.GetInt32(0),
                                          IsSwitchToggle = reader.GetBool(1),
                                          DefaultValue = reader.GetBool(2),
                                          MainLabel = reader.GetString(3),
                                          UndefinedLabel = reader.GetString(4),
                                          TrueLabel = reader.GetString(5),
                                          FalseLabel = reader.GetString(6),
                                      };

                        return dto;
                    }
                }
            }

            return null;
        }