Exemplo n.º 1
0
        /// <summary>
        /// Handles displaying the order history of a given customer ID.
        /// </summary>
        private static void HandleRequestDisplayOrderHistoryOfCustomer()
        {
            Log.Information("Handling request displaying order history of customer");
            Console.WriteLine("[?] What is the customer ID");
            string inputCustomerId = Console.ReadLine();

            Log.Information($"User entered '{inputCustomerId}' for customer id");
            if (!Int32.TryParse(inputCustomerId, out int customerId))
            {
                throw new FormatException("[!] Input for customer ID is not an integer");
            }

            if (CustomerData.GetCustomerWithId(customerId) is null)
            {
                throw new BusinessCustomerException($"[!] Customer {customerId} does not exist");
            }

            ICollection <BusinessOrder> ordersWithCustomer = OrderData.GetOrdersWithCustomerId(customerId);

            Console.WriteLine($"[*] There are {ordersWithCustomer.Count} orders for customer {customerId}");
            ordersWithCustomer.ToList().ForEach(o => Console.WriteLine(o));
            Console.WriteLine();
        }