public override Task <CreatePaymentResult> Create(CreatePaymentRequest request, ServerCallContext context) { var payment = paymentsRepository.Create(request.Amount, request.StartTimestamp.ToDateTime(), request.Interval.ToTimeSpan(), request.AccountId, request.Recipient); projectionChannel.Publish(context.RequestHeaders.GetFlowId(), new DataProjection <Models.Payment, string> { Upsert = new[] { payment } }); return(Task.FromResult(new CreatePaymentResult { Payment = mapper.Map <Payment>(payment) })); }
public override Task <CreateTransactionResult> Create(CreateTransactionRequest request, ServerCallContext context) { var transaction = transactionsRepository.Create(request.Title, request.Amount, request.Recipient, request.Sender, request.PaymentId, request.CardId); projectionChannel.Publish(context.RequestHeaders.GetFlowId(), new DataProjection <Models.Transaction, string> { Upsert = new[] { transaction } }); return(Task.FromResult(new CreateTransactionResult { Transaction = mapper.Map <Transaction>(transaction) })); }
public void Send(Update update) { _logger.LogInformation("Sending update {} to RabbitMQ", update); _publisher.Publish( "update", JsonSerializer.SerializeToUtf8Bytes(update, _jsonSerializerOptions)); }
public override async Task <TransferResponse> Transfer(TransferRequest request, ServerCallContext context) { var card = cardsRepository.GetCard(request.CardId); if (card == null) { throw new ArgumentException("Card not found."); } var blockRequestTime = DateTime.UtcNow; var title = $"{DateTime.UtcNow} card usage for a transfer worth {request.Amount} EUR"; var transfer = new Transfer { AccountId = card.AccountId, CardId = card.Id, Recipient = request.Recipient, Amount = request.Amount, Title = title }; var transferRequest = new AccountsWriteMicroservice.TransferRequest { Transfer = transfer, }; var transferResponse = await accountsClient.TransferAsync(transferRequest, context.RequestHeaders.SelectCustom()); var block = cardsRepository.CreateBlock(card.Id, transferResponse.Transaction.Id, blockRequestTime); var upsert = new CardsUpsert { Block = block }; projectionChannel.Publish(context.RequestHeaders.GetFlowId(), new DataProjection <CardsUpsert, string> { Upsert = new[] { upsert } }); return(new TransferResponse { Transaction = transferResponse.Transaction }); }
public override async Task <Empty> BatchRepayInstalments(BatchRepayInstalmentsRequest request, ServerCallContext context) { var paymentsToFinish = RepayInstalments(request); if (paymentsToFinish.Any()) { var cancelPaymentsRequest = new CancelPaymentsRequest { Ids = { paymentsToFinish } }; await paymentsClient.CancelAsync(cancelPaymentsRequest, context.RequestHeaders.SelectCustom()); } var repaidInstalments = request.Ids.Select(id => loansRepository.Get(id)).ToArray(); if (repaidInstalments.Length > 0) { projectionChannel.Publish(context.RequestHeaders.GetFlowId(), new DataProjection <Models.Loan, string> { Upsert = repaidInstalments }); } return(new Empty()); }
private static void PublishOneMessage(string updateContent) { var producer = new RabbitMqPublisher(_publisherConfig); var update = new Update { Content = updateContent }; producer.Publish( "update", JsonSerializer.SerializeToUtf8Bytes(update)); }
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 }); }
private void ButtonClick(object sender, RoutedEventArgs e) { var message = $"Button clicked at {DateTime.Now:hh:mm:ss.fff}"; _publisher.Publish(message); }