Exemplo n.º 1
0
        public Task Transfer(MessageContext context, TransferEvent inputEvent)
        {
            if (!accountsRepository.CanTransfer(inputEvent.Transfer.AccountId, inputEvent.Transfer.Recipient, inputEvent.Transfer.Amount))
            {
                throw new ArgumentException("Cannot transfer founds.");
            }

            var transfer = TransferToCreateTransactionEvent(inputEvent.Transfer);

            accountsRepository.Transfer(inputEvent.Transfer.AccountId, inputEvent.Transfer.Recipient, inputEvent.Transfer.Amount);

            //info do kogo ma wrocic
            publishingRouter.Publish(Queues.Transactions, transfer, context.FlowId, context.ReplyTo);
            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public override async Task <TransferResponse> Transfer(TransferRequest request, ServerCallContext context)
        {
            if (!accountsRepository.CanTransfer(request.Transfer.AccountId, request.Transfer.Recipient, request.Transfer.Amount))
            {
                throw new ArgumentException("Cannot transfer founds.");
            }

            var transfer = CreateRequest(request.Transfer);
            var result   = await transactionsClient.CreateAsync(transfer, context.RequestHeaders.SelectCustom());

            accountsRepository.Transfer(request.Transfer.AccountId, request.Transfer.Recipient, request.Transfer.Amount);
            return(new TransferResponse {
                Transaction = result.Transaction
            });
        }
Exemplo n.º 3
0
        public override async Task <TransferResponse> Transfer(TransferRequest request, ServerCallContext context)
        {
            if (!accountsRepository.CanTransfer(request.Transfer.AccountId, request.Transfer.Recipient, request.Transfer.Amount))
            {
                throw new ArgumentException("Cannot transfer founds.");
            }

            var transfer = CreateRequest(request.Transfer);
            var result   = await transactionsClient.CreateAsync(transfer, context.RequestHeaders.SelectCustom());

            accountsRepository.Transfer(request.Transfer.AccountId, request.Transfer.Recipient, request.Transfer.Amount);
            var affectedAccounts = new[] { accountsRepository.Get(request.Transfer.AccountId), accountsRepository.Get(request.Transfer.Recipient) };

            if (affectedAccounts.Length > 0)
            {
                projectionChannel.Publish(context.RequestHeaders.GetFlowId(), new DataProjection <Models.Account, string> {
                    Upsert = affectedAccounts
                });
            }

            return(new TransferResponse {
                Transaction = result.Transaction
            });
        }