Esempio n. 1
0
        /// <summary>
        ///  Prompts user to select the offer to transition to.
        /// </summary>
        /// <returns>offer uri</returns>
        private static string PromptForOfferUri()
        {
            GroupedOffers selectedGroupedOffers =
                OfferCatalog.Instance.GroupedOffersCollection.First(
                    groupedOffers => groupedOffers.OfferType == OfferType.IntuneAndOffice);

            Console.Write("\nSelect Offer (by index):\n ");
            foreach (
                var item in
                selectedGroupedOffers.Offers.Select((offer, index) => new { Offer = offer, Index = index }))
            {
                Console.WriteLine("{0}. {1}", item.Index + 1, item.Offer.Name);
            }
            bool done          = false;
            int  selectedIndex = -1;

            do
            {
                string input = Console.ReadLine().Trim();

                if (int.TryParse(input, out selectedIndex))
                {
                    done = true;
                }
            } while (!done);
            var selectedOffer = selectedGroupedOffers.Offers.ElementAt(selectedIndex - 1);

            return(selectedOffer.Uri);
        }
Esempio n. 2
0
        /// <summary>
        /// This method populates Order info by offer type from the console
        /// </summary>
        /// <param name="offerType">Offer type: Azure or IntuneAndOffice</param>
        /// <param name="customerCid">cid of the customer</param>
        /// <returns>order object</returns>
        private static dynamic PopulateOrderFromConsoleForOfferType(OfferType offerType, string customerCid)
        {
            GroupedOffers selectedGroupedOffers = OfferCatalog.Instance.GroupedOffersCollection.First(groupedOffers => groupedOffers.OfferType == offerType);
            dynamic       order = new
            {
                line_items            = new List <dynamic>(),
                recipient_customer_id = customerCid
            };

            int nrOfLineItems = 0;

            bool done = false;

            Console.Clear();
            do
            {
                Console.WriteLine("OfferType: {0}", offerType);
                foreach (var item in selectedGroupedOffers.Offers.Select((offer, index) => new { Offer = offer, Index = index }))
                {
                    Console.WriteLine("{0}. {1}", item.Index + 1, item.Offer.Name);
                }

                Console.Write("\nSelect Offer (by index): ");
                string input         = Console.ReadLine().Trim();
                int    selectedIndex = -1;
                if (!int.TryParse(input, out selectedIndex))
                {
                    done = false;
                }

                var selectedOffer = selectedGroupedOffers.Offers.ElementAt(selectedIndex - 1);

                bool validQuantity = false;

                do
                {
                    Console.Write("\nQuantity {0} to {1}: ", selectedOffer.MinimumQuantity, selectedOffer.MaximumQuantity);
                    input = Console.ReadLine().Trim();
                    int quantity = 1;
                    if (!int.TryParse(input, out quantity))
                    {
                        done = false;
                    }

                    if (quantity >= selectedOffer.MinimumQuantity && quantity <= selectedOffer.MaximumQuantity)
                    {
                        validQuantity = true;
                    }

                    Console.Write("\nFriendly Name (or hit Enter for none): ");
                    input = Console.ReadLine().Trim();
                    if (!string.IsNullOrWhiteSpace(input))
                    {
                        order.line_items.Add(new
                        {
                            //// has to be a unique number for each line item
                            //// recommendation is to start with 0
                            line_item_number = nrOfLineItems,

                            //// this is the offer uri for the offer that is being purchased, refer to the excel sheet for this
                            offer_uri = selectedOffer.Uri,

                            //// This is the quantity for this offer
                            quantity = quantity,

                            //// This is friendly name
                            friendlyname = input
                        });
                    }
                    else
                    {
                        order.line_items.Add(new
                        {
                            //// has to be a unique number for each line item
                            //// recommendation is to start with 0
                            line_item_number = nrOfLineItems,

                            //// this is the offer uri for the offer that is being purchased, refer to the excel sheet for this
                            offer_uri = selectedOffer.Uri,

                            //// This is the quantity for this offer
                            quantity = quantity,
                        });
                    }
                }while (!validQuantity);

                Console.Write("\nDo you want to add another line item (y/n)? ");
                input = Console.ReadLine().Trim();

                switch (input)
                {
                case "y":
                case "Y":
                    nrOfLineItems++;
                    done = false;
                    break;

                default:
                    done = true;
                    break;
                }
            }while (!done);

            return(order);
        }