// handle commands public static (Event Event, AccountState NewState) Debit (this AccountState @this, MakeTransfer transfer) { var evt = transfer.ToEvent(); var newState = @this.Apply(evt); return(evt, newState); }
public static Validation <(Event Event, AccountState NewState)> Freeze (this AccountState @this, FreezeAccount cmd) { if (@this.Status == AccountStatus.Frozen) { return(Errors.AccountNotActive); } FrozeAccount evt = cmd.ToEvent(); AccountState newState = @this.Apply(evt); return(evt as Event, newState); }
// handle commands public static Validation <(Event Event, AccountState NewState)> Debit (this AccountState @this, MakeTransfer cmd) { if (@this.Status != AccountStatus.Active) { return(Errors.AccountNotActive); } if (@this.Balance - cmd.Amount < @this.AllowedOverdraft) { return(Errors.InsufficientBalance); } DebitedTransfer evt = cmd.ToEvent(); AccountState newState = @this.Apply(evt); return(evt as Event, newState); }