コード例 #1
0
        static void Main(string[] args)
        {
            DisplayHeader();
            var service = new Inventory.InventoryServiceClient();

            ProcessInput(service);
        }
コード例 #2
0
        static void GetItemFromService(Inventory.InventoryServiceClient service, string input)
        {
            var id = new Guid(input);

            Divider("Begin Get Item from Service");
            Console.WriteLine($"Getting item {id} from service.");
            var result = service.GetInventoryItem(id);

            Console.WriteLine($"Service Returned Item: {FormatItem(result)}");
            Divider("End Get Item from Service");
        }
コード例 #3
0
        static void GetItems(Inventory.InventoryServiceClient service)
        {
            Divider("Begin GetItems");
            var result = service.GetInventoryItems();
            var index  = 1;

            foreach (var inventoryItem in result)
            {
                Console.WriteLine($"Item {index}: {FormatItem(inventoryItem)}");
                index++;
            }
            Divider("End GetItems");
        }
コード例 #4
0
        static void AddItem(Inventory.InventoryServiceClient service)
        {
            Divider("Begin Add Inventory Item");
            var item = new InventoryItem
            {
                Sku         = Guid.NewGuid(),
                ProductName = "Added Product",
                Price       = 19.95M
            };

            Console.WriteLine($"Adding Inventory Item {FormatItem(item)}");
            service.AddInventoryItem(item);
            Divider("End Add Inventory Item");
        }
コード例 #5
0
        static void ProcessInput(Inventory.InventoryServiceClient service)
        {
            var input = Console.ReadLine();

            while (!string.IsNullOrEmpty(input) && input.ToLower() != "exit")
            {
                var split = input.Split(' ');
                var newId = string.Empty;
                if (split.Length == 2)
                {
                    GetItemFromService(service, split[1]);
                }
                else
                {
                    switch (input.ToLower())
                    {
                    case "getitem":
                        GetItemFromService(service, Guid.NewGuid().ToString());
                        break;

                    case "additem":
                        AddItem(service);
                        break;

                    case "getitems":
                        GetItems(service);
                        break;

                    case "menu":
                        WriteMenu();
                        break;

                    default:
                        Console.WriteLine("Please select a valid command.");
                        WriteMenu();
                        break;
                    }
                }

                input = Console.ReadLine();
            }
        }