Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

782 B
Raw Blame
using Grand.Business.Core.Events.Checkout.Orders;
using Grand.Data;
using Grand.Domain.Catalog;
using Grand.Mediator;

namespace Grand.Business.Checkout.Events.Orders;

public class OrderDeletedEventHandler : INotificationHandler<OrderDeletedEvent>
{
    private readonly IRepository<ProductAlsoPurchased> _productAlsoPurchasedRepository;

    public OrderDeletedEventHandler(IRepository<ProductAlsoPurchased> productAlsoPurchasedRepository)
    {
        _productAlsoPurchasedRepository = productAlsoPurchasedRepository;
    }

    public Task Handle(OrderDeletedEvent notification, CancellationToken cancellationToken)
    {
        //delete product also purchased
        return _productAlsoPurchasedRepository.DeleteManyAsync(x => x.OrderId == notification.Order.Id);
    }
}