示例#1
0
        public async Task AddDepositPercents()
        {
            var deposits = await _DepositRepository.GetAllWithTrackingAsync();

            var cards = await _cardService.GetCardsAsync();

            var accounts = await _accountRepository.GetAllAsync();

            var services = await _serviceRepository.GetAllAsync();


            var bankAccountId = accounts.FirstOrDefault(x => x.Name == DepositConstants.BankAccount).Id;
            var bankServiceId = services.FirstOrDefault(x => x.Name == DepositConstants.BankDepositService).Id;
            var bankCardId    = cards.FirstOrDefault(x => x.Name == DepositConstants.BankCard).Id;

            foreach (var deposit in deposits)
            {
                if (deposit.Status == DepositConstants.Active)
                {
                    var depositType = await _depositTypeRepo.GetByIdAsync(deposit.DepositTypeId);

                    var percent = depositType.AnnualRate;

                    var account = await _accountRepository.GetByIdAsync(deposit.AccountForInterestId);

                    var bankAccount = await _accountRepository.GetByIdAsync(bankAccountId);

                    var depositPercent = ((deposit.DepositAmount * percent) / DepositConstants.Percent100);
                    bankAccount.Balance -= depositPercent;
                    account.Balance     += depositPercent;


                    var transaction = new Transactions
                    {
                        PersonalAccountId = "",
                        SenderCardId      = bankCardId,
                        ReceiverAccountId = deposit.AccountForInterestId,
                        SenderAccountId   = bankAccountId,
                        ServiceId         = bankServiceId,
                        Description       = $"add deposit percent",
                        Amount            = depositPercent,
                        Date      = DateTime.Now,
                        IsDeleted = false,
                    };

                    await _accountRepository.UpdateAsync(account);

                    await _accountRepository.UpdateAsync(bankAccount);

                    await _transactionsService.InsertAsync(transaction);


                    if (deposit.TermOfDeposit <= DateTime.Now)
                    {
                        deposit.Status = DepositConstants.Done;
                    }
                }
            }
        }