private async Task <ResponseMessage> CreateCustomer(CreatedUserIntegrationEvent integrationEvent) { var createCustomerCommand = new CreateCustomerCommand(integrationEvent.Id, integrationEvent.Name, integrationEvent.Email, integrationEvent.Cpf); using var scope = _serviceScopeFactory.CreateScope(); var mediator = scope.ServiceProvider.GetRequiredService <IMediatorHandler>(); var success = await mediator.SendCommand(createCustomerCommand); return(new ResponseMessage(success)); }
private async Task <ResponseMessage> RegisterCustomer(RegistrationUser registrationUser) { var user = await _userManager.FindByEmailAsync(registrationUser.Email); var createdUserIntegrationEvent = new CreatedUserIntegrationEvent(Guid.Parse(user.Id), registrationUser.Name, registrationUser.Email, registrationUser.Cpf); try { return(await _bus.RequestAsync <CreatedUserIntegrationEvent, ResponseMessage>(createdUserIntegrationEvent)); } catch { await _userManager.DeleteAsync(user); throw; } }