CreationAuditedAggregateRoot.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.ComponentModel.DataAnnotations.Schema;
  3. using Abp.Timing;
  4. namespace Abp.Domain.Entities.Auditing
  5. {
  6. /// <summary>
  7. /// A shortcut of <see cref="CreationAuditedAggregateRoot{TPrimaryKey}"/> for most used primary key type (<see cref="int"/>).
  8. /// </summary>
  9. [Serializable]
  10. public abstract class CreationAuditedAggregateRoot : CreationAuditedAggregateRoot<int>
  11. {
  12. }
  13. /// <summary>
  14. /// This class can be used to simplify implementing <see cref="ICreationAudited"/> for aggregate roots.
  15. /// </summary>
  16. /// <typeparam name="TPrimaryKey">Type of the primary key of the entity</typeparam>
  17. [Serializable]
  18. public abstract class CreationAuditedAggregateRoot<TPrimaryKey> : AggregateRoot<TPrimaryKey>, ICreationAudited
  19. {
  20. /// <summary>
  21. /// Creation time of this entity.
  22. /// </summary>
  23. public virtual DateTime CreationTime { get; set; }
  24. /// <summary>
  25. /// Creator of this entity.
  26. /// </summary>
  27. public virtual long? CreatorUserId { get; set; }
  28. /// <summary>
  29. /// Constructor.
  30. /// </summary>
  31. protected CreationAuditedAggregateRoot()
  32. {
  33. CreationTime = Clock.Now;
  34. }
  35. }
  36. /// <summary>
  37. /// This class can be used to simplify implementing <see cref="ICreationAudited{TUser}"/> for aggregate roots.
  38. /// </summary>
  39. /// <typeparam name="TPrimaryKey">Type of the primary key of the entity</typeparam>
  40. /// <typeparam name="TUser">Type of the user</typeparam>
  41. [Serializable]
  42. public abstract class CreationAuditedAggregateRoot<TPrimaryKey, TUser> : CreationAuditedAggregateRoot<TPrimaryKey>, ICreationAudited<TUser>
  43. where TUser : IEntity<long>
  44. {
  45. /// <summary>
  46. /// Reference to the creator user of this entity.
  47. /// </summary>
  48. [ForeignKey("CreatorUserId")]
  49. public virtual TUser CreatorUser { get; set; }
  50. }
  51. }