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.

908 B
Raw Blame
using Grand.Data;
using Grand.Domain.Customers;
using Grand.Infrastructure.Events;
using Grand.Mediator;

namespace Grand.Business.Authentication.Events;

public class CustomerDeletedEventHandler : INotificationHandler<EntityDeleted<Customer>>
{
    private readonly IRepository<ExternalAuthentication> _externalAuthenticationRepository;

    public CustomerDeletedEventHandler(IRepository<ExternalAuthentication> externalAuthenticationRepository)
    {
        _externalAuthenticationRepository = externalAuthenticationRepository;
    }

    public async Task Handle(EntityDeleted<Customer> notification, CancellationToken cancellationToken)
    {
        var externalRecords = _externalAuthenticationRepository.Table.Where(x => x.CustomerId == notification.Entity.Id)
            .ToList();
        foreach (var item in externalRecords) await _externalAuthenticationRepository.DeleteAsync(item);
    }
}