private IEnumerable <string> RepayInstalments(BatchRepayInstalmentsRequest request) { foreach (var id in request.Ids) { var totalAmountPaid = loansRepository.RepayInstalment(id); if (totalAmountPaid) { yield return(loansRepository.Get(id).PaymentId); } } }
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()); } return(new Empty()); }
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()); }