Esempio n. 1
0
 private IEnumerable <string> RepayInstalments(BatchRepayInstalmentsEvent inputEvent)
 {
     foreach (var id in inputEvent.Ids)
     {
         var totalAmountPaid = loansRepository.RepayInstalment(id);
         if (totalAmountPaid)
         {
             yield return(loansRepository.Get(id).PaymentId);
         }
     }
 }
Esempio n. 2
0
        public Task BatchRepayInstalments(MessageContext context, BatchRepayInstalmentsEvent inputEvent)
        {
            var paymentsToFinish = RepayInstalments(inputEvent);

            if (paymentsToFinish.Any())
            {
                var cancelPaymentsEvent = new CancelPaymentsEvent {
                    Ids = paymentsToFinish.ToArray()
                };
                publishingRouter.Publish(Queues.Payments, cancelPaymentsEvent, context.FlowId);
            }
            return(Task.CompletedTask);
        }
Esempio n. 3
0
        public Task Process(BatchProcess data)
        {
            var flowId   = HttpContext.Items["flowId"].ToString();
            var messages = data.Messages.Select(m => mapper.Map <UserMessage>(m)).ToArray();

            if (messages.Length > 0)
            {
                var messagesEvent = new BatchAddMessagesEvent {
                    Messages = messages
                };
                publishingRouter.Publish(Queues.Users, messagesEvent, flowId);
            }

            if (data.Transfers.Length > 0)
            {
                var transfersEvent = new BatchTransferEvent {
                    Transfers = data.Transfers
                };
                publishingRouter.Publish(Queues.Accounts, transfersEvent, flowId);
            }

            if (data.ProcessedPaymentsIds.Length > 0)
            {
                var processingTimestampEvent = new UpdateLatestProcessingTimestampEvent {
                    Ids = data.ProcessedPaymentsIds, Timestamp = data.ProcessingTimestamp
                };
                publishingRouter.Publish(Queues.Payments, processingTimestampEvent, flowId);
            }

            var instalments = data.RepaidInstalmentsIds;

            if (instalments.Length > 0)
            {
                var transfersEvent = new BatchRepayInstalmentsEvent {
                    Ids = instalments
                };
                publishingRouter.Publish(Queues.Loans, transfersEvent, flowId);
            }

            return(Task.CompletedTask);
        }