/// <summary> /// Handles a message. /// </summary> /// <param name="command">The command to handle.</param> /// <remarks> /// This method will be called when a message arrives on the bus and should contain /// the custom logic to execute when the command is received. /// </remarks> public void Handle(CustomerUpdateCommand command) { InfoAccumulator info = new InfoAccumulator(); if (!ValidateCommand(command, info)) { SendReply(info, command, response => response.CustomerId = command.CustomerId); return; } int customerId; try { customerId = CustomerIdEncryptor.DecryptCustomerId(command.CustomerId, command.CommandOriginator); } catch (Exception ex) { Log.Error(ex.Message); info.AddError("Invalid customer id."); SendReply(info, command, resp => resp.CustomerId = command.CustomerId); return; } //requests only PropertyStatusId from DB Customer customer = CustomerQueries.GetCustomerPartiallyById(customerId, o => o.PropertyStatusId); FillCustomerProperties(customer, command, info); if (info.HasErrors) { SendReply(info, command, resp => resp.CustomerId = command.CustomerId); return; } IEnumerable <CustomerAddress> addresses = FillCustomerPropertyStatusAndTimeAtAddressAndGetAddresses(command, customer, customerId); IEnumerable <CustomerPhone> phones = ExtractPhoneNumbers(command, customerId); string referenceSource = null; string visitTimes = null; if (command.Cookies != null) { referenceSource = command.Cookies.ReferenceSource; visitTimes = command.Cookies.VisitTimes; } var errors = CustomerProcessor.UpdateCustomer(customer, command.RequestedAmount, referenceSource, visitTimes, command.CampaignSourceRef, addresses, phones); if (errors.HasErrors) { if (errors.IsRetry) { RegisterError(info, command); } return; } SendReply(errors, command, response => response.CustomerId = command.CustomerId); }