public IEnumerable <IFee> Create(IVehicle vehicle) { var fees = new List <IFee>(); AddCommonFees(fees, vehicle); // todo move into table or use AOP if (vehicle is IStandardCar) { var fee = m_FeeFactory.Create <IStandardCarFee>(); fees.Add(fee); } else if (vehicle is ILuxuryCar) { var fee = m_FeeFactory.Create <ILuxuryCarFee>(); fees.Add(fee); } else if (vehicle is IMotorbike) { var fee = m_FeeFactory.Create <IMotorbikeFee>(); fees.Add(fee); } else if (vehicle is ITruck) { var fee = m_FeeFactory.Create <ITruckFee>(); fees.Add(fee); } else { throw new ArgumentException("Can't create vehicle for type '{0}'!".Inject(vehicle.GetType())); } return(fees); }
public void Withdraw(string cardNumber, decimal amount) { var card = _cardRepository.Get(cardNumber); var feeAmount = _withdrawalFeeCalculator.Calculate(amount); var amountTotal = amount + feeAmount; if (card.Balance - amountTotal < 0) { throw new InsufficientFundsException(); } card.Balance -= amountTotal; var fee = _feeFactory.Create(cardNumber, feeAmount); _feeRepository.Add(fee); }