Пример #1
0
        /// <summary>
        /// Updates action rule.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <param name="locDto">The localization DTO object.</param>
        /// <exception cref="System.ArgumentException"></exception>
        /// <exception cref="System.Data.DBConcurrencyException"></exception>
        /// <exception cref="DBConcurrencyException">Indicates stale data.</exception>
        public void UpdateActionRuleWithLocalization(ProcessActionRuleEditDto dto, ProcessActionRuleLocalizationDto locDto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
                @"
UPDATE [dbo].[ActionRules]
SET
     [ProcessId]    = @processId
    ,[Expression]   = @expression
WHERE [Id] = @id;
";

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

                using (var cmd = new SqlCommand(CommandText, cn))
                {
                    cmd.Parameters.AddWithValue("@processId", dto.ProcessId);
                    cmd.Parameters.AddWithValue("@expression", dto.Expression);
                    cmd.Parameters.AddWithValue("@id", dto.Id);

                    var rowsAffected = cmd.ExecuteNonQuery();

                    if (rowsAffected == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }

            UpdateProcessActionRuleLocalization(locDto);
        }
Пример #2
0
        /// <summary>
        /// Inserts action rule.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void InsertActionRule(ProcessActionRuleEditDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string CommandText =
                @"
INSERT INTO [dbo].[ActionRules]
(
     [Guid]
    ,[ProcessId]
    ,[Name]
    ,[Documentation]
    ,[Expression]
    ,[IsActive]
)
VALUES
(
     @guid
    ,@processId
    ,@name
    ,@documentation
    ,@expression
    ,@isActive
);
SELECT [Id]
FROM [dbo].[ActionRules]
WHERE [Id] = SCOPE_IDENTITY()";

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

                using (var cmd = new SqlCommand(CommandText, cn))
                {
                    cmd.Parameters.AddWithValue("@guid", dto.Guid);
                    cmd.Parameters.AddWithValue("@processId", dto.ProcessId);
                    cmd.Parameters.AddWithValue("@name", dto.Name);
                    cmd.Parameters.AddWithValue("@documentation", dto.Documentation);
                    cmd.Parameters.AddWithValue("@expression", dto.Expression);
                    cmd.Parameters.AddWithValue("@isActive", dto.IsActive);

                    dto.Id = (int)cmd.ExecuteScalar();
                }
            }
        }