| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- using System.Text;
- namespace Quadarax.Foundation.Core.Data.Transaction
- {
- /// <summary>
- /// Represents a single data change transaction for an entity property.
- /// Tracks the type of change, the property affected, and the associated value.
- /// </summary>
- public class DataTransaction
- {
- #region *** Enumerations ***
- /// <summary>
- /// Defines the types of data change operations.
- /// </summary>
- public enum TransactionTypeEnum
- {
- /// <summary>
- /// Indicates a new property or entity has been added.
- /// </summary>
- Add,
-
- /// <summary>
- /// Indicates a property or entity has been removed.
- /// </summary>
- Remove,
-
- /// <summary>
- /// Indicates a property value has been modified.
- /// </summary>
- Change
- }
- #endregion
- #region *** Properties ***
- /// <summary>
- /// Gets the name of the property that was changed.
- /// </summary>
- public string PropertyName { get; private set; }
-
- /// <summary>
- /// Gets the type of transaction (Add, Remove, or Change).
- /// </summary>
- public TransactionTypeEnum TransactionType { get; private set; }
-
- /// <summary>
- /// Gets the value associated with the transaction.
- /// May be null for Remove operations.
- /// </summary>
- public string? Value { get; private set; }
-
- /// <summary>
- /// Gets a value indicating whether the Value property contains a reference key
- /// rather than a direct property value.
- ///
- /// When true, the Value represents a reference to another entity (foreign key).
- /// When false, the Value represents the actual property value.
- /// </summary>
- public bool IsValueKey { get; private set; }
- #endregion
- #region *** Constructor ***
- /// <summary>
- /// Initializes a new instance of the DataTransaction class.
- /// </summary>
- /// <param name="propertyName">The name of the property that was changed.</param>
- /// <param name="transactionType">The type of transaction (Add/Remove/Change).</param>
- /// <param name="value">The new value of the property, or null if the property was removed.</param>
- /// <param name="isValueKey">True if the value represents a reference key; otherwise, false.</param>
- public DataTransaction(string propertyName, TransactionTypeEnum transactionType, string? value, bool isValueKey)
- {
- PropertyName = propertyName;
- TransactionType = transactionType;
- Value = value;
- IsValueKey = isValueKey;
- }
- #endregion
- #region *** Public Overrides ***
- /// <summary>
- /// Returns a string representation of the data transaction.
- /// </summary>
- /// <returns>A formatted string containing the transaction details.</returns>
- public override string ToString()
- {
- var sb = new StringBuilder();
- sb.Append("Type=").Append(TransactionType).Append(";");
- sb.Append("Field=").Append(PropertyName).Append(";");
- sb.Append("Value=").Append(Value == null ? "<NULL>" : Value).Append(";");
- return sb.ToString();
- }
- #endregion
- }
- }
|