public async Task RewardDepositors(CancellationToken stoppingToken) { var cards = await Context.Cards .Include(d => d.DepositBranch) .ThenInclude(d => d.Deposits) .Include(d => d.CheckingBranch) .Include(d => d.CreditBranch) .ToListAsync(stoppingToken); foreach (var card in cards) { foreach (var deposit in card.DepositBranch.Deposits) { if (deposit.Term <= 0) { await _checkingBranchService.TopUp(card.CardId, deposit.DepSum); Context.Remove(deposit); } else { if (!deposit.PaymentsToDeposit) { if (deposit.CanBeTerminated) { await _checkingBranchService.TopUp(card.CardId, (deposit.DepSum * ((decimal)(deposit.Percent - 0.5)) / 100)); } else { await _checkingBranchService.TopUp(card.CardId, (deposit.DepSum * ((decimal)deposit.Percent) / 100)); } } else { if (deposit.CanBeTerminated) { deposit.DepSum += (deposit.DepSum * ((decimal)(deposit.Percent - 0.5)) / 100); } else { deposit.DepSum += (deposit.DepSum * ((decimal)deposit.Percent) / 100); } } } deposit.Term -= 1; } } await Context.SaveChangesAsync(stoppingToken); }
public async Task TopUp(int cardId, decimal amount) { await _branchService.TopUp(cardId, amount); }