Esempio n. 1
0
        static void DisplaySpecificOrder(IProject0Repository projectRepository)
        {
            int orderId       = 0;
            var specificOrder = new Orders();

            while (orderId == 0 && specificOrder.Id == 0)
            {
                _io.Output("Enter Order Id: \n");
                try
                {
                    orderId       = Int32.Parse(_io.Input());
                    specificOrder = projectRepository.GetOrders().First(o => o.Id == orderId);
                }
                catch (ArgumentException ex)
                {
                    _io.Output("Order Id Invalid.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            var productName  = projectRepository.GetProductById(specificOrder.ProductId).Name;
            var customerName = projectRepository.GetCustomerById(specificOrder.CustomerId).FirstName + " " + projectRepository.GetCustomerById(specificOrder.CustomerId).LastName;

            // locationName = projectRepository.GetLocationsById(specificOrder.CustomerId).LocationName;
            //_io.Output($"ID: {specificOrder.Id} Product Name: {productName} Quantity: {specificOrder.Quantity} " +
            // $"Location: {locationName} Customer Name: {customerName} \n");
            _io.Output($"ID: {specificOrder.Id} Product Name: {productName} Quantity: {specificOrder.Quantity} " +
                       $" Customer Name: {customerName} \n");
        }
Esempio n. 2
0
        /// <summary>
        /// Write a list of orders to console with optional search-by-customerId.
        /// </summary>
        public static void DisplayOrders(IProject0Repository repository)
        {
            Console.Write("    Enter a CustomerId to filter orders? (Y/N) : ");
            string doSearch = Console.ReadLine().ToLower();
            int?   search   = null;

            if (doSearch == "y" || doSearch == "yes")
            {
                do
                {
                    Console.Write("        ");
                    try
                    {
                        search = int.Parse(Console.ReadLine());
                    }
                    catch
                    {
                        search = null;
                    }
                } while (search == null);
            }

            IEnumerable <IOrder> orders = repository.GetOrders(search);

            foreach (IOrder o in orders)
            {
                Console.WriteLine(o.OrderId + " " + o.CustomerId + " " + o.LocationId + " " + o.OrderTime + " " + o.OrderTotal);
                var lines = o.OrderLines;
                foreach (var ol in lines)
                {
                    Console.WriteLine("    " + ol.Quantity + " : " + ol.Product.Name + " " + ol.Product.BestBy + " " + ol.Product.UnitPrice);
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            Console.Write("   Press Enter to continue");
            Console.ReadLine();
            Console.WriteLine();
        }
Esempio n. 3
0
        static void DisplayCustomerHistory(IProject0Repository projectRepository)
        {
            _io.Output("Select an Customer: \n");
            var customers    = projectRepository.GetCustomers();
            var customerList = customers.ToList <Customer>();
            int customerId   = 0;

            while (customerId == 0)
            {
                foreach (var item in customerList)
                {
                    _io.Output($"{item.FirstName} {item.LastName} \n");
                }
                string[] customerInput = _io.Input().Split(' ');
                try
                {
                    customerId = customers.First(c => c.FirstName.ToLower() == customerInput[0] && c.LastName.ToLower() == customerInput[1]).Id;
                }
                catch (ArgumentException ex)
                {
                    _io.Output("Name Invalid. It does not match any in our database.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            var orderHistory = projectRepository.GetOrders().Where(o => o.CustomerId == customerId).ToList();

            foreach (var item in orderHistory)
            {
                var productName  = projectRepository.GetProductById(item.ProductId).Name;
                var customerName = projectRepository.GetCustomerById(item.CustomerId).FirstName + " " + projectRepository.GetCustomerById(item.CustomerId).LastName;
                //var locationName = projectRepository.GetLocationsById(item.CustomerId).LocationName;
                //_io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " +
                //            $"Location: {locationName} Customer Name: {customerName} \n");
                _io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " +
                           $" Customer Name: {customerName} \n");
            }
        }
Esempio n. 4
0
        static void DisplayLocationHistory(IProject0Repository projectRepository)
        {
            _io.Output("Select an Location: \n");
            var locations    = projectRepository.GetLocations();
            var locationList = locations.ToList <StoreLocation>();
            int locationId   = 0;

            while (locationId == 0)
            {
                foreach (var item in locationList)
                {
                    _io.Output(item.LocationName + "\n");
                }
                string locationInput = _io.Input();
                try
                {
                    //get store id
                    locationId = locations.First(l => l.LocationName.ToLower() == locationInput).Id;
                }
                catch (ArgumentException ex)
                {
                    _io.Output("Location Id Invalid.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            var orderHistory = projectRepository.GetOrders().Where(o => o.StoreLocationId == locationId).ToList();

            foreach (var item in orderHistory)
            {
                var productName  = projectRepository.GetProductById(item.ProductId).Name;
                var customerName = projectRepository.GetCustomerById(item.CustomerId).FirstName + " " + projectRepository.GetCustomerById(item.CustomerId).LastName;
                var locationName = projectRepository.GetLocationsById(item.CustomerId).LocationName;
                _io.Output($"ID: {item.Id} Product Name: {productName} Quantity: {item.Quantity} " +
                           $" Customer Name: {customerName} \n");
            }
        }