Пример #1
0
        static void NewUser(IProject0Repository projectRepository)
        {
            var customer = new Customer();

            while (customer.FirstName == null || customer.LastName == null)
            {
                _io.Output("Adding New User: \n");
                _io.Output("Enter a new firstName: ");
                string firstName = _io.Input();
                _io.Output("Enter a new lastName: ");
                string lastName = _io.Input();
                try
                {
                    customer.FirstName = firstName;
                    customer.LastName  = lastName;
                }
                catch (ArgumentException ex)
                {
                    s_logger.Info(ex);
                    Console.WriteLine(ex.Message);
                }
            }
            _io.Output("User Added. \n \n");
            projectRepository.AddCustomer(customer);
            projectRepository.Save();
        }
Пример #2
0
        /// <summary>
        /// Get new customer information from user and add to system.
        /// </summary>
        public static void AddCustomer(IProject0Repository repository)
        {
            // Get first name from user
            string firstName = null;

            do
            {
                Console.Write("    Enter First Name: ");
                firstName = Console.ReadLine();
                if (firstName.Length < 2)
                {
                    firstName = null;
                }
            } while (firstName == null);

            // Get last name from user
            string lastName = null;

            do
            {
                Console.Write("    Enter Last Name: ");
                lastName = Console.ReadLine();
                if (lastName.Length < 2)
                {
                    lastName = null;
                }
            } while (lastName == null);

            Console.Write("    Enter Address? (Y/N) : ");
            string doAddress = Console.ReadLine().ToLower();
            string address = null, city = null, state = null, country = null, postalCode = null;

            if (doAddress == "y" || doAddress == "yes")
            {
                Console.Write("    Enter Address: ");
                address = Console.ReadLine();
                // Check Address Format Here

                Console.Write("    Enter City: ");
                city = Console.ReadLine();
                // Check City Format Here

                Console.Write("    Enter State: ");
                state = Console.ReadLine();
                // Check State Format Here

                Console.Write("    Enter Country: ");
                country = Console.ReadLine();
                // Check Country Format Here

                Console.Write("    Enter Postal Code: ");
                postalCode = Console.ReadLine();
                // Check Postal Code Format Here
            }

            Console.Write("    Enter Phone Number? (Y/N) : ");
            string toPhone = Console.ReadLine().ToLower();
            string phone   = null;

            if (toPhone == "y" || toPhone == "yes")
            {
                Console.Write("    Enter Phone Number: ");
                phone = Console.ReadLine();
                // Check Phone Number Format Here
            }

            string email = null;

            do
            {
                Console.Write("    Enter Email: ");
                email = Console.ReadLine();
                // Check Email Format Here
            } while (email == null);


            ICustomer customer = new Project0.Customers.Customer(firstName, lastName, address, city, state, country, postalCode, phone, email);

            repository.AddCustomer(customer);
            repository.Save();

            Console.WriteLine();
        }
Пример #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.");
        }