public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, [Queue("loan-applications")] IAsyncCollector <LoanApplicationReceived> messageQueue, ILogger log) { log.LogInformation($"{nameof(MakeApplication)} started."); var readDataOperation = await GetDataFromRequestBodyAsync <LoanApplicationRequest>(req).ConfigureAwait(false); if (!readDataOperation.Status) { log.LogInformation("Invalid loan application received"); return(new BadRequestObjectResult("Please pass a valid request")); } var loanApplication = readDataOperation.Data; // // Send the loan application request to the queue // var loanApplicationReceivedEvent = new LoanApplicationReceived { Name = loanApplication.Name, Age = loanApplication.Age }; await messageQueue.AddAsync(loanApplicationReceivedEvent).ConfigureAwait(false); return(new OkObjectResult($"Hi {loanApplication.Name}! Your loan application is in progress.")); }
public static void Run([QueueTrigger("loan-applications", Connection = "")] LoanApplicationReceived request, [Blob("accepted-applications/{rand-guid}")] out string acceptedApplication, [Blob("rejected-applications/{rand-guid}")] out string rejectedApplication, ILogger log) { acceptedApplication = null; rejectedApplication = null; log.LogInformation($"{nameof(ScoreApplication)} function started."); var isValid = !string.IsNullOrWhiteSpace(request.Name) && request.Age >= 18; if (isValid) { log.LogInformation($"{request.Name} application is valid. Proceed with the loan"); acceptedApplication = JsonConvert.SerializeObject(new LoanApplicationAccepted { Name = request.Name, AcceptedDate = DateTime.UtcNow }); } else { var reason = $"{request.Name} application is invalid. The person seemed to be under aged or do not have a name!"; log.LogInformation(reason); rejectedApplication = JsonConvert.SerializeObject(new LoanApplicationRejected { Name = request.Name, Reason = reason }); } }
public void Handle(LoanApplicationReceived message) { State.ApplicationId = message.ApplicationId; SendSagaCommand(new SendWelcomeEmail(this) { Name = message.Name, Email = message.From, Amount = message.Amount, Description = message.Description }); SendSagaCommand(new SendNotificationToAdministrator(this) { Amount = message.Amount }); }