1
+ namespace CqrsSqlServer . Shared . Events ;
2
+
3
+ /// <summary>
4
+ /// Used to distinguish product events from commands
5
+ /// </summary>
6
+ public interface IProductEvent : IWithProductId
7
+ {
8
+ }
9
+
10
+ public record ProductCreated ( string ProductId , string ProductName , decimal Price ) : IProductEvent ;
11
+
12
+ public record ProductSold ( ProductOrder Order , decimal UnitPrice , bool BackOrdered = false ) : IProductEvent ,
13
+ IWithOrderId , IComparable < ProductSold >
14
+ {
15
+ public string ProductId => Order . ProductId ;
16
+
17
+ public string OrderId => Order . OrderId ;
18
+
19
+ public decimal TotalPrice => Order . Quantity * UnitPrice ;
20
+
21
+ public int CompareTo ( ProductSold ? other )
22
+ {
23
+ if ( other == null ) return 1 ;
24
+
25
+ return Order . Timestamp . CompareTo ( other . Order . Timestamp ) ;
26
+ }
27
+ }
28
+
29
+ public enum InventoryChangeReason
30
+ {
31
+ Fulfillment ,
32
+ SupplyIncrease ,
33
+
34
+ /// <summary>
35
+ /// i.e. Theft or spoilage
36
+ /// </summary>
37
+ Lost
38
+ }
39
+
40
+ public record ProductInventoryChanged ( string ProductId , int Quantity , DateTime Timestamp ,
41
+ InventoryChangeReason Reason = InventoryChangeReason . Fulfillment ) : IProductEvent ,
42
+ IComparable < ProductInventoryChanged >
43
+ {
44
+ public int CompareTo ( ProductInventoryChanged ? other )
45
+ {
46
+ if ( ReferenceEquals ( this , other ) ) return 0 ;
47
+ if ( ReferenceEquals ( null , other ) ) return 1 ;
48
+ return Timestamp . CompareTo ( other . Timestamp ) ;
49
+ }
50
+ }
51
+
52
+ public enum ProductWarningReason
53
+ {
54
+ /// <summary>
55
+ /// Warning once inventory is running low.
56
+ /// </summary>
57
+ LowSupply ,
58
+ NoSupply
59
+ }
60
+
61
+ public record ProductInventoryWarningEvent ( string ProductId , ProductWarningReason Reason , DateTime Timestamp ,
62
+ string Message ) : IProductEvent , IComparable < ProductInventoryWarningEvent >
63
+ {
64
+ public int CompareTo ( ProductInventoryWarningEvent ? other )
65
+ {
66
+ if ( ReferenceEquals ( this , other ) ) return 0 ;
67
+ return ReferenceEquals ( null , other ) ? 1 : Timestamp . CompareTo ( other . Timestamp ) ;
68
+ }
69
+ }
0 commit comments