private CashoutAggregate(
            Guid operationId,
            Guid clientId,
            string blockchainType,
            string blockchainAssetId,
            string hotWalletAddress,
            string toAddress,
            decimal amount,
            string assetId,
            CashoutState state)
        {
            StartMoment = DateTime.UtcNow;

            OperationId       = operationId;
            ClientId          = clientId;
            BlockchainType    = blockchainType;
            BlockchainAssetId = blockchainAssetId;
            HotWalletAddress  = hotWalletAddress;
            ToAddress         = toAddress;
            Amount            = amount;
            AssetId           = assetId;

            State  = state;
            Result = CashoutResult.Unknown;
        }
        private bool SwitchState(CashoutState expectedState, CashoutState nextState)
        {
            if (State < expectedState)
            {
                // Throws to retry and wait until aggregate will be in the required state
                throw new InvalidAggregateStateException(State, expectedState, nextState);
            }

            if (State > expectedState)
            {
                // Aggregate already in the next state, so this event can be just ignored
                return(false);
            }

            State = nextState;

            return(true);
        }
        private CashoutAggregate(
            string version,
            CashoutState state,
            CashoutResult result,
            DateTime startMoment,
            DateTime?operationFinishMoment,
            Guid operationId,
            Guid clientId,
            string blockchainType,
            string blockchainAssetId,
            string hotWalletAddress,
            string toAddress,
            decimal amount,
            string assetId,
            string transactionHash,
            decimal?transactionAmount,
            decimal?fee,
            string error,
            Guid?batchId)
        {
            Version = version;
            State   = state;
            Result  = result;

            StartMoment           = startMoment;
            OperationFinishMoment = operationFinishMoment;

            OperationId       = operationId;
            ClientId          = clientId;
            BlockchainType    = blockchainType;
            BlockchainAssetId = blockchainAssetId;
            HotWalletAddress  = hotWalletAddress;
            ToAddress         = toAddress;
            Amount            = amount;
            AssetId           = assetId;

            TransactionHash   = transactionHash;
            TransactionAmount = transactionAmount;
            Fee     = fee;
            Error   = error;
            BatchId = batchId;
        }
 public static CashoutAggregate Restore(
     string version,
     CashoutState state,
     CashoutResult result,
     DateTime startMoment,
     DateTime?operationFinishMoment,
     Guid operationId,
     Guid clientId,
     string blockchainType,
     string blockchainAssetId,
     string hotWalletAddress,
     string toAddress,
     decimal amount,
     string assetId,
     string transactionHash,
     decimal?transactionAmount,
     decimal?fee,
     string error,
     Guid?batchId)
 {
     return(new CashoutAggregate(
                version,
                state,
                result,
                startMoment,
                operationFinishMoment,
                operationId,
                clientId,
                blockchainType,
                blockchainAssetId,
                hotWalletAddress,
                toAddress,
                amount,
                assetId,
                transactionHash,
                transactionAmount,
                fee,
                error,
                batchId));
 }