public async Task <CustomerDto> Handle(CreateCustomerCommand request, CancellationToken cancellationToken) { if (await _customerRepository.EmailExistAsync(request.Email)) { throw new ArgumentException($"The email : {request.Email} already exists!", nameof(request.Email)); } var customer = new Domain.Core.Models.Customer(request.Name, request.Email, request.Address, request.Age, request.PhoneNumber); _customerRepository.Add(customer); if (await _customerRepository.SaveChangesAsync() == 0) { throw new ApplicationException(); } await _mediator.Publish(new Domain.Core.Events.CustomerCreatedEvent(customer.Id), cancellationToken); var customerDto = _customerDxos.MapCustomerDto(customer); return(customerDto); }
public CustomerDto MapCustomerDto(Domain.Core.Models.Customer customer) { return(_mapper.Map <Domain.Core.Models.Customer, CustomerDto>(customer)); }