public async Task Consume(ConsumeContext <RefusePayment> context) { var id = context.CorrelationId.GetValueOrDefault(); var reason = context.Message.Reason; var payment = await dbContext.Payments.FindAsync(id); logger.LogInformation($"Received {nameof(RefusePayment)} message with Id = '{id}'"); if (payment is null) { logger.LogInformation($"'{id}' does not exists in this context. Rejecting, will retry in a few."); throw new PaymentNotFoundException(); } logger.LogInformation($"'{id}' exists in this context."); payment.IsPaymentAccepted = false; await dbContext.SaveChangesAsync(); logger.LogInformation($"'{id}' refused."); await context.Publish <PaymentRefused>(new { context.CorrelationId, context.Message.Reason }); }
public async Task Consume(ConsumeContext <OrderRegistered> context) { var id = context.CorrelationId.GetValueOrDefault(); var quantity = context.Message.Quantity; logger.LogInformation($"Received {nameof(OrderRegistered)} message with Id = '{id}' and Quantity = {quantity}."); dbContext.Add(new Payment { Id = id, Amount = quantity * 2.5f }); await dbContext.SaveChangesAsync(); logger.LogInformation($"Payment '{id}' created. Waiting for stock and user input."); await context.Publish <PaymentCreated>(new { context.CorrelationId }); }
public async Task Consume(ConsumeContext <StockBookingFailed> context) { var id = context.CorrelationId.GetValueOrDefault(); var reason = context.Message.Reason; var payment = await dbContext.Payments.FindAsync(id); if (payment is null) { return; } logger.LogInformation($"'{id}' exists in this context. Deleting because of {nameof(StockBookingFailed)} message with reason = '{reason}'."); dbContext.Payments.Remove(payment); await dbContext.SaveChangesAsync(); await context.Publish <PaymentCancelled>(new { context.CorrelationId }); }
public async Task Consume(ConsumeContext <StockBooked> context) { var id = context.CorrelationId.GetValueOrDefault(); var payment = await dbContext.Payments.FindAsync(id); logger.LogInformation($"Received {nameof(StockBooked)} message with Id = '{id}'"); if (payment is null) { logger.LogInformation($"'{id}' does not exists in this context. Rejecting, will retry in a few."); throw new PaymentNotFoundException(); } logger.LogInformation($"'{id}' exists in this context."); payment.IsStockBooked = true; await dbContext.SaveChangesAsync(); logger.LogInformation($"'{id}' updated."); }