예제 #1
0
        /// <summary>
        /// Get new order information from user and add to system.
        /// </summary>
        public static void AddOrder(IProject0Repository repository)
        {
            List <Products.IProduct> products = new List <Products.IProduct>(repository.GetProducts());

            // Get CustomerId
            int customerId = -1;

            do
            {
                Console.Write("    Enter CustomerId: ");
                try
                {
                    customerId = int.Parse(Console.ReadLine());
                }
                catch
                {
                    customerId = -1;
                }
            } while (customerId < 0);

            // Get LocationId
            int locationId = -1;

            do
            {
                Console.Write("    Enter LocationId: ");
                try
                {
                    locationId = int.Parse(Console.ReadLine());
                }
                catch
                {
                    locationId = -1;
                }
            } while (locationId < 0);

            // Get OrderTime
            DateTime orderTime = DateTime.Now;

            // Get OrderLines
            List <Orders.OrderLine> orderLines = new List <Orders.OrderLine>();
            int  count = 0;
            bool done  = false;

            do
            {
                // Get OrderLine ProductId
                int productId = -1;
                do
                {
                    Console.Write("    Enter ProductId: ");
                    try
                    {
                        productId = int.Parse(Console.ReadLine());
                    }
                    catch
                    {
                        productId = -1;
                    }
                } while (productId < 0);

                // Get OrderLine Quantity
                int quantity = -1;
                do
                {
                    Console.Write("    Enter Quantity: ");
                    try
                    {
                        quantity = int.Parse(Console.ReadLine());
                    }
                    catch
                    {
                        quantity = -1;
                    }
                } while (quantity < 1);

                orderLines.Add(new Orders.OrderLine
                {
                    Product  = products[productId],
                    Quantity = quantity
                });
                count++;


                Console.Write("    Enter another OrderLine? (Y/N) : ");
                string check = Console.ReadLine().ToLower();
                if (check == "y" || check == "yes")
                {
                    done = false;
                }
                else
                {
                    done = true;
                }
            } while (count < 1 || done == false);



            IOrder order = new Project0.Orders.Order
            {
                CustomerId = customerId,
                LocationId = locationId,
                OrderTime  = orderTime,
                OrderLines = orderLines
            };

            repository.AddOrder(order);

            Console.WriteLine();
        }
예제 #2
0
        public static void DisplayOptions(IProject0Repository repository)
        {
            while (true)
            {
                Console.WriteLine("c: Create A New Order");
                Console.WriteLine("q: To Return Back to the Main Menu");

                Console.WriteLine();

                string userinput = Console.ReadLine();


                if (userinput == "c")
                {
                    int customerid;

                    while (true)
                    {
                        Console.WriteLine("Please Enter The Customer ID\n");
                        string customeridstring = Console.ReadLine();

                        if (int.TryParse(customeridstring, out customerid))
                        {
                            break;
                        }
                        else if (customeridstring == "q")
                        {
                            break;
                        }
                    }

                    int storeid;

                    while (true)
                    {
                        Console.WriteLine("Please Enter The Store ID\n");
                        string storeids = Console.ReadLine();

                        if (int.TryParse(storeids, out storeid))
                        {
                            break;
                        }
                        else if (storeids == "q")
                        {
                            break;
                        }
                    }
                    DateTime OrderTime = DateTime.Now;
                    try
                    {
                        Project.Library.Order order = new Project.Library.Order(customerid, storeid, OrderTime);
                        repository.AddOrder(order);
                    }
                    catch (ArgumentException exception)
                    {
                        Console.WriteLine("Could not Create Order");
                        Console.WriteLine(exception.Message);
                    }
                }

                else if (userinput == "q")
                {
                    Console.WriteLine("Returning to Main Menu\n");
                    break;
                }
            }
        }
예제 #3
0
        static void MakeOrder(Customer customer, IProject0Repository projectRepository)
        {
            _io.Output("Choose a location: \n");
            //display all locations
            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("Store name input invalid.");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            //display available products
            _io.Output("Choose a product: \n");
            var products      = projectRepository.GetProducts();
            var productList   = products.Where(p => p.StoreLocationId == locationId && p.Stock > 0).ToList <Product>();
            var productObject = new Product();

            while (productObject.Name == null)
            {
                foreach (var item in productList)
                {
                    _io.Output($"Name: {item.Name} Stock: {item.Stock} Price: {item.Price} \n");
                }
                var productInput = _io.Input();
                try
                {
                    productObject = productList.First(p => p.Name.ToLower() == productInput);
                }
                catch (Exception ex)
                {
                    _io.Output("Product name or Quantity input invalid. ");
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }

            var quantityInput = 0;
            var quantityBool  = true;

            while (quantityBool)
            {
                _io.Output("Choose a quantity: \n");
                quantityInput = Int32.Parse(_io.Input());
                if (quantityInput > productObject.Stock)
                {
                    _io.Output("Quantity too large. \n");
                }
                else
                {
                    quantityBool = false;
                }
            }
            productObject.Stock = productObject.Stock - quantityInput;
            projectRepository.UpdateProduct(productObject);
            DateTime timeStamp = DateTime.Now;
            var      newOrder  = new Orders {
                StoreLocationId = locationId, CustomerId = customer.Id, ProductId = productObject.Id, Quantity = quantityInput
            };

            projectRepository.AddOrder(newOrder);
            projectRepository.Save();
            _io.Output("Order Complete.");
        }