コード例 #1
0
        public void Execute(IList <string> args)
        {
            string output;

            if (args == null || !args.Any())
            {
                var result = _cmdCoffeeApi.GetProducts().Result as IEnumerable <dynamic>;

                output = _outputGenerator.GenerateTable(result, new[] { "code", "name", "price usd", "weight (oz)" },
                                                        p => p.code, p => p.name, p => p.priceUsd, p => p.weightInOunces);
            }
            else
            {
                var productCode = args.FirstOrDefault();

                var result = _cmdCoffeeApi.GetProducts().Result as IEnumerable <dynamic>;

                var product = result?.FirstOrDefault(p => p.code == productCode?.ToUpper());

                output = product != null
                    ? (string)_outputGenerator.GeneratePairs(product, "Product Details")
                    : $"no product found: {productCode}";
            }

            _outputWriter.WriteLine(output);
        }
コード例 #2
0
        public void Execute(IList <string> args)
        {
            if (args == null || !args.Any())
            {
                var result = _cmdCoffeeApi.GetOrders().Result as IEnumerable <dynamic>;

                _outputWriter.WriteLine(_outputGenerator.GenerateTable(result, new[] { "order key", "product name", "status", "total (usd)", "date created" },
                                                                       o => o.orderKey, o => o.productName, o => o.status, o => o.total, o => o.dateCreated));
            }
            else
            {
                var orderKey = args.FirstOrDefault();

                var order = _cmdCoffeeApi.GetOrder(orderKey).Result;

                if (order != null)
                {
                    _outputWriter.WriteLine(_outputGenerator.GeneratePairs((IEnumerable <KeyValuePair <string, object> >)order));
                    return;
                }

                _outputWriter.WriteError($"No order found: {orderKey}");
            }
        }
コード例 #3
0
        public void Execute(IList <string> args)
        {
            try
            {
                var productCode = args.First();

                if (string.IsNullOrEmpty(productCode))
                {
                    _writer.WriteError("product-code required");
                    return;
                }

                var promoCode = args.Count() > 1 ? args[1] : string.Empty;

                if (_appSettings.ShippingAddress == null)
                {
                    _writer.WriteError("shipping address required");
                    return;
                }

                var result = _cmdCoffeeApi.PostOrder(productCode, _appSettings.ShippingAddress, promoCode).Result;

                var order = result.orderDetails;

                _writer.WriteLine(_outputGenerator.GeneratePairs(new Dictionary <string, object>
                {
                    { "product", order.productName },
                    { "sub-total", order.subTotal },
                    { "discount", order.discount },
                    { "total", order.total }
                }, "Please confirm order details"));

                _writer.WriteLine(
                    $"{_outputGenerator.GeneratePairs((IEnumerable<KeyValuePair<string, JToken>>) order.shippingAddress, "shipping address")}");

                if (!_writer.AskYesNo("Is this correct?"))
                {
                    _writer.WriteLine(
                        "If your address is not correct, please update your address in app-settings.json and try again.");
                    return;
                }

                _writer.WriteLine($"\nCheck out our return policy: {result.returnPolicy}");

                if (!_writer.AskYesNo("Does that work for you?"))
                {
                    _writer.AwaitAnyKey(
                        $"Bummer. Feel free to shoot us an email to {_appSettings.ContactEmail} to share your concerns.");
                    return;
                }

                _writer.WriteLine($"\nWe'll get started on your order as soon as we receive payment.");
                _writer.WriteLine($"Payment will be accepted until {result.paymentExpiration}");
                _writer.AwaitAnyKey("Press enter to see payment methods");

                var paymentOptions = new List <dynamic>();
                paymentOptions.AddRange(result.paymentOptions as IEnumerable <dynamic>);
                var paypalAddress = $"{_appSettings.PayPalAddress}{order.total}USD";
                paymentOptions.Add(new { Name = "PayPal.Me", Value = new { amount = order.total, address = paypalAddress } });

                _writer.WriteLine(_outputGenerator.GenerateTable(paymentOptions, new [] { "Type", "Amount", "Address" },
                                                                 o => o.Name, o => o.Value.amount, o => o.Value.address));

                _writer.WriteLine($"Make sure you include your order key ({order.orderKey}) in the payment note.");

                _writer.AwaitAnyKey();
            }
            catch (Exception ex)
            {
                _writer.WriteError(ex);
            }
        }