示例#1
0
        public async Task <IAccountModel?> ProcessTransactionCheckedEventAsync(IAccountModel accountModel)
        {
            var existingAccount = await _accountsService.GetAccountByIdAsync(accountModel.Id.ToGuid());

            if (existingAccount != null)
            {
                if (accountModel.IsBlocked())
                {
                    existingAccount.SetBlocked();
                }
                var updatedAccount = await _accountsService.UpdateAccountAsync(existingAccount);

                return(updatedAccount?.ToAccountModel <AccountDto>());
            }

            var createdAccount = await _accountsService.CreateAccountAsync(accountModel.ToAccountEntity());

            return(createdAccount?.ToAccountModel <AccountDto>());
        }
        public async Task <AccountDto?> ProcessAccountIsCheckedEventAsync(IAccountModel accountModel)
        {
            var accountEntity = await _accountsService.GetAccountByIdAsync(accountModel.Id.ToGuid());

            if (accountEntity != null)
            {
                if (accountModel.IsBlocked())
                {
                    accountEntity.SetBlocked();
                }
                else
                {
                    if (accountModel.IsApproved())
                    {
                        accountEntity.SetApproval();
                    }
                    else
                    {
                        accountEntity.SetDenial();
                    }
                }

                // Optimistic Concurrency Control: update incrementing the version
                var updatedAccount = await _accountsService.UpdateAccountAsync(accountEntity);

                if (updatedAccount != null)
                {
                    await _publishEndpoint.Publish(updatedAccount.ToAccountEvent <AccountUpdatedEvent>());

                    await _publishEndpoint.Publish(updatedAccount.ToNotificationEvent());

                    return(updatedAccount.ToAccountModel <AccountDto>());
                }
            }

            return(null);
        }