public async Task <IAccountModel?> EvaluateAccountPendingAsync(IAccountModel accountCheckCommand)
        {
            if (
                string.IsNullOrEmpty(accountCheckCommand.ProfileId) ||
                string.IsNullOrEmpty(accountCheckCommand.Id)
                )
            {
                return(null);
            }

            var isCreationAllowed = await _licenseManager.EvaluateNewEntityAsync(accountCheckCommand);

            if (isCreationAllowed)
            {
                accountCheckCommand.SetApproval();
            }
            else
            {
                accountCheckCommand.SetDenial();
            }

            var approvedEntity = await _approvalsService.CreateApprovalAsync(
                accountCheckCommand.ToApprovalEntity()
                );

            if (approvedEntity != null)
            {
                var accountIsCheckedEvent = approvedEntity.ToAccountModel <AccountIsCheckedEvent>(accountCheckCommand);
                await _publishEndpoint.Publish(accountIsCheckedEvent);

                return(accountIsCheckedEvent);
            }

            return(null);
        }
Пример #2
0
        public async Task <TransactionDto?> CreateNewTransactionAsync(ITransactionModel transactionModel)
        {
            if (
                string.IsNullOrEmpty(transactionModel.ProfileId) ||
                transactionModel.AccountId == Guid.Empty.ToString() ||
                !await _licenseManager.EvaluateNewEntityAsync(transactionModel)
                )
            {
                return(null);
            }

            // Optimistic Concurrency Control: set the sequential number
            var sequencedTransaction = await _concurrencyManager.SetNextSequentialNumber(transactionModel);

            var newTransaction = await _transactionsService.CreateTransactionAsync(
                sequencedTransaction.ToTransactionEntity()
                );

            if (newTransaction != null)
            {
                await _publishEndpoint.Publish(newTransaction.ToTransactionModel <TransactionCreatedEvent>());

                await _publishEndpoint.Publish(newTransaction.ToTransactionModel <TransactionCheckCommand>());

                return(newTransaction.ToTransactionModel <TransactionDto>());
            }

            return(null);
        }
Пример #3
0
        public async Task <ITransactionModel?> EvaluateTransactionAsync(ITransactionModel transactionCreatedEvent)
        {
            if (
                string.IsNullOrEmpty(transactionCreatedEvent.ProfileId) ||
                string.IsNullOrEmpty(transactionCreatedEvent.AccountId)
                )
            {
                return(null);
            }

            var isTransactionAllowed = await _licenseManager.EvaluateNewEntityAsync(transactionCreatedEvent);

            if (isTransactionAllowed)
            {
                transactionCreatedEvent.SetApproval();
            }
            else
            {
                transactionCreatedEvent.SetDenial();
            }

            var processedEntity = await _billingsService.CreateBillingAsync(
                transactionCreatedEvent.ToBillingEntity()
                );

            if (processedEntity != null)
            {
                var transactionProcessedEvent = processedEntity.ToTransactionModel <TransactionIsCheckedEvent>(
                    transactionCreatedEvent
                    );
                await _publishEndpoint.Publish(transactionProcessedEvent);

                return(transactionProcessedEvent);
            }

            return(null);
        }