Newer
Older
DistributedTracing / src / Shipping / CancelShippingLabelHandler.cs
@Derek Comartin Derek Comartin on 16 May 2022 704 bytes Init
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using NServiceBus;
using Sales.Contracts;

namespace Shipping
{
    public class CancelShippingLabelHandler : IHandleMessages<OrderCancelled>
    {
        private readonly ShippingDbContext _dbContext;

        public CancelShippingLabelHandler(ShippingDbContext dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task Handle(OrderCancelled message, IMessageHandlerContext context)
        {
            var order = await _dbContext.ShippingLabels.SingleAsync(x => x.OrderId == message.OrderId);
            order.Cancelled = true;
            await _dbContext.SaveChangesAsync();
        }
    }
}