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.

1.0 KB
Raw Blame
using Grand.Business.Core.Interfaces.Customers;
using Grand.Web.Commands.Models.Customers;
using Grand.Mediator;

namespace Grand.Web.Commands.Handler.Customers;

public class SubAccountDeleteCommandHandler : IRequestHandler<SubAccountDeleteCommand, (bool success, string error)>
{
    private readonly ICustomerService _customerService;

    public SubAccountDeleteCommandHandler(ICustomerService customerService)
    {
        _customerService = customerService;
    }

    public async Task<(bool success, string error)> Handle(SubAccountDeleteCommand request,
        CancellationToken cancellationToken)
    {
        ArgumentNullException.ThrowIfNull(request.CurrentCustomer);

        var customer = await _customerService.GetCustomerById(request.CustomerId);
        if (customer == null || customer.OwnerId != request.CurrentCustomer.Id)
            return (false, "You are not owner of this account");

        //delete customer
        await _customerService.DeleteCustomer(customer);

        return (true, string.Empty);
    }
}