private void WithdrawMoney(object sender, ElapsedEventArgs e)
{
var withdrawnSum = 0.0m;
foreach (var v in _parking.Vehicles)
{
var defaultFee = Settings.Tariffs[v.VehicleType];
var withdraw = defaultFee;
if (v.Balance < defaultFee)
{
var missingAmount = defaultFee - v.Balance;
var penalty = missingAmount * Settings.PenaltyFactor;
withdraw = (defaultFee - missingAmount) + penalty;
}
v.Balance -= withdraw;
_parking.Transactions.Add(
new TransactionInfo()
{
PassedAt = DateTime.Now,
VehicleId = v.Id,
Sum = withdraw
}
);
withdrawnSum += withdraw;
}
_parking.Balance += withdrawnSum;
}