private static OrderManagerServiceClient BuyOneOfEachProduct(ProductManagerService.Product[] products) { //Simula uma compra Console.WriteLine("==== BUY ONE OF EACH PRODUCTS ===="); var clientOrders = new OrderManagerServiceClient(); clientOrders.Open(); clientOrders.CreateOrder(products.Select(product => new Product { Id = product.Id, Name = product.Name, Description = product.Description, Price = product.Price, Quantity = 1 }).ToArray()); Console.WriteLine("==== END BUY ONE OF EACH PRODUCTS ===="); return(clientOrders); }
static void Main(string[] args) { //Obtem produtos do WCF OrderManagerServiceClient client = null; try { client = new OrderManagerServiceClient(); client.Open(); var stayInMenu = true; do { Console.WriteLine("Enter Y to read next order or anything else to cancel"); var enteredInput = Console.ReadLine()?.ToUpperInvariant(); switch (enteredInput) { case "Y": var order = client.GetNextOrder(); if (order != null) { foreach (var product in order) { Console.WriteLine($"{product.Name} - R${product.Price} - Qty:{product.Quantity}"); } } break; default: stayInMenu = false; break; } } while (stayInMenu); } finally { client?.Close(); } }