public IEnumerable<IEvent> Register(int id, RegisterNewCustomerCommand cmd, CompanyIntelligenceReport report) { if (report.IsBankrupt) yield return new CustomerRegistrationWasRefused(cmd.RegistrationId, "Customer's company is bankrupt"); var isPremium = IsPremiumCompany(report); yield return ApplyEvent(new NewCustomerWasRegistered(cmd.RegistrationId, id, isPremium, cmd.FirstName, cmd.LastName, cmd.Email, cmd.WorksForCompanyID)); }
public void Register(CustomerViewModel customerViewModel) { RegisterNewCustomerCommand registerNewCustomerCommand = _mapper.Map <RegisterNewCustomerCommand>(customerViewModel); _bus.SendCommand(registerNewCustomerCommand); }
public async Task <IActionResult> RegisterNewCustomer(RegisterNewCustomerCommand command) { var response = await _mediator.Send(command); if (response.IsFailure) { return(BadRequest(response.ErrorResponse)); } return(Created("", new { response.PayLoad.Id, response.PayLoad.Name, response.PayLoad.CreatedAt })); }
public async Task <IActionResult> RegisterNewCustomer(RegisterNewCustomerCommand command) { var response = await _mediator.Send(command); if (response.IsFailure) { return(BadRequest(response.ErrorResponse)); } return(Created($"{Request.Scheme}://{Request.Host}/api/v{API_VERSION}/customers/{response.PayLoad.Id}", response.PayLoad)); }
public void Handle(RegisterNewCustomerCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } var customer = new Customer(Guid.NewGuid(), message.Nome, message.Email, message.BirthDate); if (_clienteRepository.GetByEmail(customer.Email) != null) { Bus.RaiseEvent(new DomainNotification(message.MessageType, "The customer e-mail has already been taken.")); return; } _clienteRepository.Add(customer); if (Commit()) { Bus.RaiseEvent(new CustomerRegisteredEvent(customer.Id, customer.Name, customer.Email, customer.BirthDate)); } }