DataTransaction.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Text;
  2. namespace Quadarax.Foundation.Core.Data.Transaction
  3. {
  4. /// <summary>
  5. /// Represents a single data change transaction for an entity property.
  6. /// Tracks the type of change, the property affected, and the associated value.
  7. /// </summary>
  8. public class DataTransaction
  9. {
  10. #region *** Enumerations ***
  11. /// <summary>
  12. /// Defines the types of data change operations.
  13. /// </summary>
  14. public enum TransactionTypeEnum
  15. {
  16. /// <summary>
  17. /// Indicates a new property or entity has been added.
  18. /// </summary>
  19. Add,
  20. /// <summary>
  21. /// Indicates a property or entity has been removed.
  22. /// </summary>
  23. Remove,
  24. /// <summary>
  25. /// Indicates a property value has been modified.
  26. /// </summary>
  27. Change
  28. }
  29. #endregion
  30. #region *** Properties ***
  31. /// <summary>
  32. /// Gets the name of the property that was changed.
  33. /// </summary>
  34. public string PropertyName { get; private set; }
  35. /// <summary>
  36. /// Gets the type of transaction (Add, Remove, or Change).
  37. /// </summary>
  38. public TransactionTypeEnum TransactionType { get; private set; }
  39. /// <summary>
  40. /// Gets the value associated with the transaction.
  41. /// May be null for Remove operations.
  42. /// </summary>
  43. public string? Value { get; private set; }
  44. /// <summary>
  45. /// Gets a value indicating whether the Value property contains a reference key
  46. /// rather than a direct property value.
  47. ///
  48. /// When true, the Value represents a reference to another entity (foreign key).
  49. /// When false, the Value represents the actual property value.
  50. /// </summary>
  51. public bool IsValueKey { get; private set; }
  52. #endregion
  53. #region *** Constructor ***
  54. /// <summary>
  55. /// Initializes a new instance of the DataTransaction class.
  56. /// </summary>
  57. /// <param name="propertyName">The name of the property that was changed.</param>
  58. /// <param name="transactionType">The type of transaction (Add/Remove/Change).</param>
  59. /// <param name="value">The new value of the property, or null if the property was removed.</param>
  60. /// <param name="isValueKey">True if the value represents a reference key; otherwise, false.</param>
  61. public DataTransaction(string propertyName, TransactionTypeEnum transactionType, string? value, bool isValueKey)
  62. {
  63. PropertyName = propertyName;
  64. TransactionType = transactionType;
  65. Value = value;
  66. IsValueKey = isValueKey;
  67. }
  68. #endregion
  69. #region *** Public Overrides ***
  70. /// <summary>
  71. /// Returns a string representation of the data transaction.
  72. /// </summary>
  73. /// <returns>A formatted string containing the transaction details.</returns>
  74. public override string ToString()
  75. {
  76. var sb = new StringBuilder();
  77. sb.Append("Type=").Append(TransactionType).Append(";");
  78. sb.Append("Field=").Append(PropertyName).Append(";");
  79. sb.Append("Value=").Append(Value == null ? "<NULL>" : Value).Append(";");
  80. return sb.ToString();
  81. }
  82. #endregion
  83. }
  84. }