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 <CreatePayment> context) { var id = context.CorrelationId.GetValueOrDefault(); var amount = context.Message.Amount; logger.LogInformation($"Received {nameof(CreatePayment)} message with Id = '{id}' and Amount = {amount}."); dbContext.Add(new Payment { Id = id, Amount = amount }); await dbContext.SaveChangesAsync(); logger.LogInformation($"Payment '{id}' created."); await context.Publish <PaymentCreated>(new { context.CorrelationId, context.Message.Amount }); }
public async Task Consume(ConsumeContext <CancelPayment> context) { var id = context.CorrelationId.GetValueOrDefault(); var reason = context.Message.Reason; var payment = await dbContext.Payments.FindAsync(id); logger.LogInformation($"Received {nameof(CancelPayment)} 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. Deleting because of {nameof(CancelPayment)} message with reason = '{reason}'."); dbContext.Payments.Remove(payment); await dbContext.SaveChangesAsync(); await context.Publish <PaymentCancelled>(new { context.CorrelationId }); }