public async Task <int> Handle(WithdrawnOperationCommand request, CancellationToken cancellationToken)
        {
            var accountRequest = await _accountOperationRequestRepository
                                 .GetByIdWithRelatedEntitiesAsync(request.OperationRequestId);

            if (accountRequest == null)
            {
                _notificationContext.AddNotification("RequestNotFound", "Request not found");
                return(0);
            }

            if (!accountRequest.AccountHasFounds)
            {
                _notificationContext.AddNotification("InsuficientFounds", "Account Has Insuficient founds");
                return(0);
            }
            accountRequest.Account.CurrentBalance -= accountRequest.Amount;

            var operation = accountRequest.GenerateOperation();

            operation.Validate();

            if (!operation.Valid)
            {
                _notificationContext.AddNotifications(operation.ValidationResult);
                return(0);
            }

            _accountOperationRepository.Add(operation);

            return(await _unitOfWork.CommitAsync());
        }
        public async Task <int> Handle(IncomeRentabilizationCommand request, CancellationToken cancellationToken)
        {
            /*
             * Note: reference for fórmula :
             *  https://blog.paranabanco.com.br/investimento/cdi-diario/#:~:text=somente%20entre%20bancos.-,Como%20%C3%A9%20feito%20o%20c%C3%A1lculo,das%20taxas%20das%20transa%C3%A7%C3%B5es%20interbanc%C3%A1rias.
             *
             * Access Date: 18/03/2021
             */
            var account = await _accountRepository.GetByIdAsync(request.AccountId);

            if (account == null)
            {
                _notificationContext.AddNotification("AccountNotFound", "Account Not Found");
                return(0);
            }

            if (account.CurrentBalance == 0)
            {
                _notificationContext.AddNotification("NoBalance", "Current balance is 0");
                return(0);
            }

            var cidFactor = 1 + (_incomeConfiguration.CIDPercentual / 100);

            var anualFactor = (double)1 / _incomeConfiguration.AnualFactor;

            var amountOperation = (decimal)Math.Pow(cidFactor, anualFactor) * account.CurrentBalance;

            _accountOperationRepository.Add(new AccountOperation()
            {
                AccountId     = account.Id,
                Note          = "Transação de rendimento diário",
                Amount        = amountOperation - account.CurrentBalance,
                OperationType = OperationType.IncomeRentabilization,
                OperationDate = DateTime.Now
            });;

            account.CurrentBalance = amountOperation;

            return(await _unitOfWork.CommitAsync());
        }