private Transfer.Type GetValidType(MoneyAccount destination) { if (AccountType == Type.Cash && destination.AccountType == Type.Debit) { return(Transfer.Type.Deposit); } switch (destination.AccountType) { case Type.Savings: return(Transfer.Type.Saving); case Type.Prepaid: return(Transfer.Type.Recharge); case Type.Credit: return(Transfer.Type.Payment); default: { if (AccountType == Type.Savings || AccountType == Type.Debit) { return(Transfer.Type.Withdrawal); } return(Transfer.Type.Unknown); } } }
private void Validate(MoneyAccount destination) { var isNotAllowedSource = AccountType == Type.Credit || AccountType == Type.Prepaid; var isNotAllowedForCredit = destination.AccountType == Type.Credit && AccountType != Type.Debit; if (isNotAllowedSource || isNotAllowedForCredit) { throw new Exception($"{AccountType} to {destination.AccountType} is not valid."); } }
public Transfer TransferTo(MoneyAccount destination) { var transfer = new Transfer { Source = this, Destination = destination }; Validate(transfer.Destination); transfer.TransferType = GetValidType(transfer.Destination); return(transfer); }