/// <summary> /// Inserts expressions 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 InsertExpressionsStep(ExpressionsStepDto 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 = @" DELETE FROM [dbo].[stepExpressions] WHERE [FieldId] = @p_FieldId; INSERT INTO [dbo].[stepExpressions] ([FieldId] ,[DefaultExpression] ,[CalculatedExpression] ,[IsDisabled]) VALUES (@p_FieldId ,@p_DefaultExpression ,@p_CalculatedExpression ,@p_IsDisabled)"; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_FieldId", dto.FieldId); command.Parameters.AddWithValue("@p_DefaultExpression", dto.DefaultExpression ?? DBNull.Value); command.Parameters.AddWithValue("@p_CalculatedExpression", dto.CalculatedExpression ?? DBNull.Value); command.Parameters.AddWithValue("@p_IsDisabled", dto.IsDisabled); var rowsAffetcted = command.ExecuteNonQuery(); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }
/// <summary> /// Updates expressions. /// </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 UpdateExpressions(ExpressionsStepDto 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 [stepExpressions] SET [DefaultExpression] = @p_DefaultExpression, [CalculatedExpression] = @p_CalculatedExpression, [IsDisabled] = @p_IsDisabled WHERE FieldId = @p_FieldId"; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_FieldId", data.FieldId); command.Parameters.AddWithValue("@p_DefaultExpression", data.DefaultExpression ?? DBNull.Value); command.Parameters.AddWithValue("@p_CalculatedExpression", data.CalculatedExpression ?? DBNull.Value); command.Parameters.AddWithValue("@p_IsDisabled", data.IsDisabled); var rowsAffetcted = command.ExecuteNonQuery(); if (rowsAffetcted == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }