Exemplo n.º 1
0
        private async Task <INewCustomer> MakeNewCustomer()
        {
            INewCustomer newCustomer = null;
            string       firstName, lastName;
            bool         tryAgain;

            do
            {
                tryAgain = false;

                _io.Output.Write("Enter their first name:");
                firstName = _io.Input.ReadInput();
                _io.Output.Write("Enter their last name:");
                lastName = _io.Input.ReadInput();

                if (string.IsNullOrWhiteSpace(firstName))
                {
                    _io.Output.Write("The first name cannot be empty.");
                    await TryAgain("Try again with a new customer name", "Cancel adding customer", () => tryAgain = true);
                }
                else
                {
                    newCustomer = new NewCustomer(firstName, lastName);
                }
            }while (tryAgain);

            return(newCustomer);
        }
Exemplo n.º 2
0
        private async Task AddCustomer()
        {
            ICustomerRepository repo = _mainDatabase.CustomerRepository;

            INewCustomer customer = await MakeNewCustomer();

            if (customer == null)
            {
                return;
            }

            _io.Output.Write("Adding customer...");
            await repo.CreateCustomerAsync(customer);

            _io.Output.Write($"'{customer}' has been added to the database.");
        }
        public void Submit(INewCustomer customer)
        {
            var factory = GetConnectionFactory();
              using (var connection = factory.CreateConnection())
              {
            using (var channel = connection.CreateModel())
            {
              DeclareExchange(channel);

              var message = JsonConvert.SerializeObject(customer);
              var body = Encoding.UTF8.GetBytes(message);

              channel.BasicPublish(Constants.EXCHANGE_NAME, Constants.NEW_CUSTOMER_EVENT, null, body);
              Console.WriteLine(" [x] Sent '{0}':'{1}'", Constants.NEW_CUSTOMER_EVENT, message);
            }
              }
        }