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.

863 B
Raw Blame
using Grand.Module.Api.Commands.Models.Customers;
using Grand.Module.Api.DTOs.Customers;
using Grand.Module.Api.Extensions;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Mediator;

namespace Grand.Module.Api.Commands.Handlers.Customers;

public class AddCustomerAddressCommandHandler : IRequestHandler<AddCustomerAddressCommand, AddressDto>
{
    private readonly ICustomerService _customerService;

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

    public async Task<AddressDto> Handle(AddCustomerAddressCommand request, CancellationToken cancellationToken)
    {
        var address = request.Address.ToEntity();
        address.Id = "";
        await _customerService.InsertAddress(address, request.Customer.Id);
        return address.ToModel();
    }
}