Esempio n. 1
0
        public async Task <bool> Handle(ApplyCreditCommand request, CancellationToken token)
        {
            var credit = request.Credit;

            credit.PercentCredit = 1;
            credit.Status        = true;

            await _creditRepository.AddCredit(credit);

            //счет, на который нужно перечислить средства
            var currentAccount = await _bankAccountRepository.Accounts.FirstAsync(account => account.IdAccount == credit.IdAccount);

            if (currentAccount != null)
            {
                currentAccount.Amount += credit.Amount;
                await _bankAccountRepository.SaveAccount(currentAccount);

                await _mediator.Send(new BankAccountOperationCommand(credit.IdAccount, "Зачисление суммы кредита",
                                                                     credit.Amount));

                _logger.Log(LogLevel.Information, $"Account: {credit.IdAccount} Loan amount credited to the account");

                return(true);
            }

            return(false);
        }