@@ -51,11 +51,8 @@ public static void CreateFloat(this FloatAggregate aggregate,
5151 public static void RecordCreditPurchase ( this FloatAggregate aggregate , DateTime creditPurchasedDate , Decimal amount , Decimal costPrice )
5252 {
5353 aggregate . ValidateFloatIsAlreadyCreated ( ) ;
54-
55- Boolean isCreditADuplicate = aggregate . IsCreditADuplicate ( creditPurchasedDate , amount , costPrice ) ;
56- if ( isCreditADuplicate )
57- return ;
58-
54+ aggregate . ValidateCreditIsNotADuplicate ( creditPurchasedDate , amount , costPrice ) ;
55+
5956 FloatCreditPurchasedEvent floatCreditPurchasedEvent = new FloatCreditPurchasedEvent ( aggregate . AggregateId , aggregate . EstateId ,
6057 creditPurchasedDate , amount , costPrice ) ;
6158
@@ -64,7 +61,10 @@ public static void RecordCreditPurchase(this FloatAggregate aggregate, DateTime
6461
6562 public static void RecordTransactionAgainstFloat ( this FloatAggregate aggregate , Guid transactionId , Decimal transactionAmount ) {
6663 aggregate . ValidateFloatIsAlreadyCreated ( ) ;
67- aggregate . ValidateTransactionIsNotADuplicate ( transactionId ) ;
64+
65+ Boolean isTransactionADuplicate = aggregate . IsTransactionADuplicate ( transactionId ) ;
66+ if ( isTransactionADuplicate )
67+ return ;
6868
6969 FloatDecreasedByTransactionEvent floatDecreasedByTransactionEvent = new FloatDecreasedByTransactionEvent ( aggregate . AggregateId , aggregate . EstateId , transactionId , transactionAmount ) ;
7070
@@ -88,18 +88,19 @@ public static void ValidateFloatIsNotAlreadyCreated(this FloatAggregate aggregat
8888 }
8989 }
9090
91- public static Boolean IsCreditADuplicate ( this FloatAggregate aggregate , DateTime creditPurchasedDate , Decimal amount , Decimal costPrice ) {
91+ public static void ValidateCreditIsNotADuplicate ( this FloatAggregate aggregate , DateTime creditPurchasedDate , Decimal amount , Decimal costPrice )
92+ {
9293 Boolean isDuplicate = aggregate . Credits . Any ( c => c . costPrice == costPrice && c . amount == amount && c . creditPurchasedDate == creditPurchasedDate ) ;
93- return isDuplicate ;
94+ if ( isDuplicate == true )
95+ {
96+ throw new InvalidOperationException ( $ "Float Aggregate Id { aggregate . AggregateId } already has a credit with this information recorded") ;
97+ }
9498 }
9599
96- public static void ValidateTransactionIsNotADuplicate ( this FloatAggregate aggregate , Guid transactionId )
100+ public static Boolean IsTransactionADuplicate ( this FloatAggregate aggregate , Guid transactionId )
97101 {
98102 Boolean isDuplicate = aggregate . Transactions . Any ( c => c . transactionId == transactionId ) ;
99- if ( isDuplicate == true )
100- {
101- throw new InvalidOperationException ( $ "Float Aggregate Id { aggregate . AggregateId } already has a transaction with this Id { transactionId } recorded") ;
102- }
103+ return isDuplicate ;
103104 }
104105 }
105106
0 commit comments