33namespace DotNetElements . Core ;
44
55public interface IEntity < TKey > : IHasKey < TKey >
6- where TKey : notnull , IEquatable < TKey > ;
6+ where TKey : notnull , IEquatable < TKey > ;
77
88public interface ICreationAuditedEntity < TKey > : IEntity < TKey >
9- where TKey : notnull , IEquatable < TKey >
9+ where TKey : notnull , IEquatable < TKey >
1010{
11- Guid CreatorId { get ; }
11+ Guid CreatorId { get ; }
1212
13- DateTimeOffset CreationTime { get ; }
13+ DateTimeOffset CreationTime { get ; }
1414
15- void SetCreationAudited ( Guid creatorId , DateTimeOffset creationTime ) ;
15+ void SetCreationAudited ( Guid creatorId , DateTimeOffset creationTime ) ;
1616}
1717
1818public interface IAuditedEntity < TKey > : ICreationAuditedEntity < TKey >
19- where TKey : notnull , IEquatable < TKey >
19+ where TKey : notnull , IEquatable < TKey >
2020{
21- Guid ? LastModifierId { get ; }
21+ Guid ? LastModifierId { get ; }
2222
23- DateTimeOffset ? LastModificationTime { get ; }
23+ DateTimeOffset ? LastModificationTime { get ; }
2424
25- bool HasChanged => LastModificationTime is null ;
25+ bool HasChanged => LastModificationTime is null ;
2626
27- void SetModificationAudited ( Guid lastModifierId , DateTimeOffset lastModificationTime ) ;
27+ void SetModificationAudited ( Guid lastModifierId , DateTimeOffset lastModificationTime ) ;
2828}
2929
3030public interface ISoftDelete
3131{
32- bool IsDeleted { get ; }
32+ bool IsDeleted { get ; }
3333
34- void Delete ( ) ;
34+ void Delete ( ) ;
3535}
3636
3737public interface IHasDeletionTime : ISoftDelete
3838{
39- DateTimeOffset ? DeletionTime { get ; }
39+ DateTimeOffset ? DeletionTime { get ; }
4040
41- void Delete ( DateTimeOffset deletionTime ) ;
41+ void Delete ( DateTimeOffset deletionTime ) ;
4242}
4343
4444public interface IDeletionAuditedEntity : IHasDeletionTime
4545{
46- Guid ? DeleterId { get ; }
46+ Guid ? DeleterId { get ; }
4747
48- void Delete ( Guid deleterId , DateTimeOffset deletionTime ) ;
48+ void Delete ( Guid deleterId , DateTimeOffset deletionTime ) ;
4949}
5050
5151public interface IUpdatable < TFrom >
5252{
53- void Update ( TFrom from , IAttachRelatedEntity attachRelatedEntity ) ;
53+ void Update ( TFrom from ) ;
54+ }
55+
56+ public interface IUpdatableEx < TFrom >
57+ {
58+ void Update ( TFrom from , Guid currentUser , DateTimeOffset currentTime , IAttachRelatedEntity attachRelatedEntity ) ;
5459}
5560
5661public interface IRelatedEntity < TSelf , TKey >
57- where TSelf : IEntity < TKey > , IRelatedEntity < TSelf , TKey >
58- where TKey : notnull , IEquatable < TKey >
62+ where TSelf : IEntity < TKey > , IRelatedEntity < TSelf , TKey >
63+ where TKey : notnull , IEquatable < TKey >
5964{
60- static abstract TSelf CreateRefById ( TKey id ) ;
65+ static abstract TSelf CreateRefById ( TKey id ) ;
6166}
6267
6368public abstract class Entity { }
6469
6570public abstract class Entity < TKey > : Entity , IEntity < TKey >
66- where TKey : notnull , IEquatable < TKey >
71+ where TKey : notnull , IEquatable < TKey >
6772{
68- public TKey Id { get ; protected set ; } = default ! ;
73+ public TKey Id { get ; protected set ; } = default ! ;
6974}
7075
7176public class CreationAuditedEntity < TKey > : Entity < TKey > , ICreationAuditedEntity < TKey >
72- where TKey : notnull , IEquatable < TKey >
77+ where TKey : notnull , IEquatable < TKey >
7378{
74- public Guid CreatorId { get ; private set ; }
79+ public Guid CreatorId { get ; private set ; }
7580
76- public DateTimeOffset CreationTime { get ; private set ; }
81+ public DateTimeOffset CreationTime { get ; private set ; }
7782
78- public void SetCreationAudited ( Guid creatorId , DateTimeOffset creationTime )
79- {
80- if ( CreatorId != default )
81- throw new InvalidOperationException ( "Can not set audit parameters of a already created entity" ) ;
83+ public void SetCreationAudited ( Guid creatorId , DateTimeOffset creationTime )
84+ {
85+ if ( CreatorId != default )
86+ throw new InvalidOperationException ( "Can not set audit parameters of a already created entity" ) ;
8287
83- CreatorId = creatorId ;
84- CreationTime = creationTime ;
85- }
88+ CreatorId = creatorId ;
89+ CreationTime = creationTime ;
90+ }
8691}
8792
8893public class AuditedEntity < TKey > : CreationAuditedEntity < TKey > , IAuditedEntity < TKey >
89- where TKey : notnull , IEquatable < TKey >
94+ where TKey : notnull , IEquatable < TKey >
9095{
91- public Guid ? LastModifierId { get ; private set ; }
96+ public Guid ? LastModifierId { get ; private set ; }
9297
93- public DateTimeOffset ? LastModificationTime { get ; private set ; }
98+ public DateTimeOffset ? LastModificationTime { get ; private set ; }
9499
95- public void SetModificationAudited ( Guid lastModifierId , DateTimeOffset lastModificationTime )
96- {
97- LastModifierId = lastModifierId ;
98- LastModificationTime = lastModificationTime ;
99- }
100+ public void SetModificationAudited ( Guid lastModifierId , DateTimeOffset lastModificationTime )
101+ {
102+ LastModifierId = lastModifierId ;
103+ LastModificationTime = lastModificationTime ;
104+ }
100105}
101106
102107public class PersistentEntity < TKey > : AuditedEntity < TKey > , IDeletionAuditedEntity
103- where TKey : notnull , IEquatable < TKey >
108+ where TKey : notnull , IEquatable < TKey >
104109{
105- public bool IsDeleted { get ; private set ; }
110+ public bool IsDeleted { get ; private set ; }
106111
107- public Guid ? DeleterId { get ; private set ; }
112+ public Guid ? DeleterId { get ; private set ; }
108113
109- public DateTimeOffset ? DeletionTime { get ; private set ; }
114+ public DateTimeOffset ? DeletionTime { get ; private set ; }
110115
111- public void Delete ( Guid deleterId , DateTimeOffset deletionTime )
112- {
113- if ( IsDeleted )
114- throw new InvalidOperationException ( "Can not delete an already deleted entity" ) ;
116+ public void Delete ( Guid deleterId , DateTimeOffset deletionTime )
117+ {
118+ if ( IsDeleted )
119+ throw new InvalidOperationException ( "Can not delete an already deleted entity" ) ;
115120
116- IsDeleted = true ;
117- DeleterId = deleterId ;
118- DeletionTime = deletionTime ;
119- }
121+ IsDeleted = true ;
122+ DeleterId = deleterId ;
123+ DeletionTime = deletionTime ;
124+ }
120125
121- [ EditorBrowsable ( EditorBrowsableState . Never ) ]
122- public void Delete ( DateTimeOffset deletionTime ) => throw new NotImplementedException ( ) ;
126+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
127+ public void Delete ( DateTimeOffset deletionTime ) => throw new NotImplementedException ( ) ;
123128
124- [ EditorBrowsable ( EditorBrowsableState . Never ) ]
125- public void Delete ( ) => throw new NotImplementedException ( ) ;
129+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
130+ public void Delete ( ) => throw new NotImplementedException ( ) ;
126131}
0 commit comments