private void WithdrawMoney object sender ElapsedEventArgs var withdraw

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
}