/// <summary> /// Updates process data index field. /// </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 UpdateProcessDataIndexField(ProcessDataIndexFieldDto dto) { if (dto == null) throw new ArgumentNullException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" UPDATE [dbo].[ProcessDataIndexField] SET [DataIndexId] = @p_DataIndexId ,[FieldGuidId] = @p_FieldGuidId ,[IsKey] = @p_IsKey WHERE [Id] = @p_Id; "; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_Id", dto.Id); command.Parameters.AddWithValue("@p_DataIndexId", dto.DataIndexId); command.Parameters.AddWithValue("@p_FieldGuidId", dto.FieldGuidId); command.Parameters.AddWithValue("@p_IsKey", dto.IsKey); if (command.ExecuteNonQuery() == 0) { throw new DBConcurrencyException(Resources.StaleDataException); } } } }
/// <summary> /// Inserts process data index field. /// </summary> /// <param name="dto">The DTO object.</param> /// <exception cref="System.ArgumentException">The input DTO is null.</exception> public void InsertProcessDataIndexField(ProcessDataIndexFieldDto dto) { if (dto == null) throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, Resources.NullArguementException, "dto")); const string CommandText = @" INSERT INTO [dbo].[ProcessDataIndexField] ( [DataIndexId] ,[FieldGuidId] ,[IsKey] ) VALUES ( @p_DataIndexId ,@p_FieldGuidId ,@p_IsKey ); SELECT [Id] FROM [dbo].[ProcessDataIndexField] WHERE [Id] = SCOPE_IDENTITY()"; using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false)) { var connection = ctx.Connection; using (var command = new SqlCommand(CommandText, connection)) { command.Parameters.AddWithValue("@p_DataIndexId", dto.DataIndexId); command.Parameters.AddWithValue("@p_FieldGuidId", dto.FieldGuidId); command.Parameters.AddWithValue("@p_IsKey", dto.IsKey); dto.Id = (int)command.ExecuteScalar(); } } }