Пример #1
0
        /// <summary>
        /// Updates approval required step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentException">The input DTO is null.</exception>
        /// <exception cref="System.Data.DBConcurrencyException">Indicates stale data</exception>
        public void UpdateApprovalRequiredStep(ApprovalRequiredStepDto dto)
        {
            if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
UPDATE [dbo].[ApprovalRequiredFieldStep]
SET
     [FieldId] = @fieldId
    ,[ReadyForApprovalStateGuid] = @readyForApprovalStateGuid
    ,[ApprovedStateGuid] = @approvedStateGuid
    ,[RejectedStateGuid] = @rejectedStateGuid
    ,[LastModifiedOn] = getdate()
WHERE [Id] = @id;
";

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

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);
                    cmd.Parameters.AddWithValue("@readyForApprovalStateGuid", dto.ReadyForApprovalStateGuid);
                    cmd.Parameters.AddWithValue("@approvedStateGuid", dto.ApprovedStateGuid);
                    cmd.Parameters.AddWithValue("@rejectedStateGuid", dto.RejectedStateGuid);
                    cmd.Parameters.AddWithValue("@id", dto.Id);

                    var rowsAffected = cmd.ExecuteNonQuery();

                    if (rowsAffected == 0)
                    {
                        throw new DBConcurrencyException(Resources.StaleDataException);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Inserts approval required step.
        /// </summary>
        /// <param name="dto">The DTO object.</param>
        /// <exception cref="System.ArgumentNullException">The input DTO is null.</exception>
        public void InsertApprovalRequiredStep(ApprovalRequiredStepDto dto)
        {
            if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto"));

            const string Sql =
                @"
INSERT INTO [dbo].[ApprovalRequiredFieldStep]
(
     [FieldId]
    ,[ReadyForApprovalStateGuid]
    ,[ApprovedStateGuid]
    ,[RejectedStateGuid]
    ,[LastModifiedOn]
)
VALUES
(
     @fieldId
    ,@readyForApprovalStateGuid
    ,@approvedStateGuid
    ,@rejectedStateGuid
    ,getdate()
);

SELECT [Id]
FROM   [dbo].[ApprovalRequiredFieldStep]
WHERE  [Id] = SCOPE_IDENTITY()";

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

                using (var cmd = new SqlCommand(Sql, cn))
                {
                    cmd.Parameters.AddWithValue("@fieldId", dto.FieldId);
                    cmd.Parameters.AddWithValue("@readyForApprovalStateGuid", dto.ReadyForApprovalStateGuid);
                    cmd.Parameters.AddWithValue("@approvedStateGuid", dto.ApprovedStateGuid);
                    cmd.Parameters.AddWithValue("@rejectedStateGuid", dto.RejectedStateGuid);

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