public Order(List <ProductsInOrder> productsToBuy, CustomerClass customer) { countOrder++; this.orderNr = countOrder; customerInOrder = customer; foreach (ProductsInOrder item in productsToBuy) { productsinOrder.Add(item); } }
public void registerNewCustomer() { CustomerClass ManualCustomerRegistration = new CustomerClass(); string systemInput = "0"; while (systemInput != "9") { try { Console.WriteLine("Please folow instructions below"); Console.Write("Firstname: "); ManualCustomerRegistration.FirstName = Console.ReadLine(); Console.Write("Lastname: "); ManualCustomerRegistration.LastName = Console.ReadLine(); Console.Write("Address : "); ManualCustomerRegistration.HomeAddress = Console.ReadLine(); Console.Write("ZipCode: "); ManualCustomerRegistration.HomeZipCode = Convert.ToInt32(Console.ReadLine()); Console.Write("Social security number : "); ManualCustomerRegistration.SSN = Console.ReadLine(); ManualCustomerRegistration.CustomerNo = ManualCustomerRegistration.SSN; Console.WriteLine("\nYou have provided the following details, would you like to add the customer?\n"); Console.Write("Y/N : "); string answer = Console.ReadLine(); if (answer.ToLower() == "y") { listCustomers.Add(ManualCustomerRegistration); Console.WriteLine("Customer: {0} was added, press any key to go back", ManualCustomerRegistration.FirstName); Console.ReadLine(); systemInput = "9"; } else if (answer.ToLower() == "n") { Console.WriteLine("Customer registration was dismissed"); systemInput = "9"; } else { Console.WriteLine("Please select either Y or N"); } } catch (FormatException) { Console.WriteLine("Invalid number, please press any key and fill out the form again"); System.Console.ReadKey(); } } }
public void InitiateCustomerBase() //Initiating 10 random customers to the business system using slumpa.net API { int i = 0; while (i < 10) { string httpClient = new HttpClient().GetStringAsync("http://www.slumpa.net/api/").Result; JObject token = JObject.Parse(httpClient); CustomerClass NewPerson = new CustomerClass(); NewPerson.FirstName = (string)token["name"]; NewPerson.LastName = (string)token["lastname"]; NewPerson.CustomerNo = (string)token["ssn"]; listCustomers.Add(NewPerson); i++; } }
public void placeCustomerOrder() { List <ProductsInOrder> productsToBuy = new List <ProductsInOrder>(); bool truish = true; do { Console.WriteLine(" -- Customers -- "); foreach (CustomerClass items in listCustomers) { Console.WriteLine("Customer number: {0} - Firstname: {1} - Lastname: {2} -", items.CustomerNo, items.FirstName, items.LastName); } Console.WriteLine("Choose a customer or write Exit to return to: "); string userInputCustomer = Console.ReadLine(); if (userInputCustomer.ToUpper() == "EXIT") { truish = false; return; } CustomerClass customerSearch = listCustomers.Find(x => x.CustomerNo == userInputCustomer); if (customerSearch != null) { bool addItem = true; do { try { bool haveProduct = false; Console.WriteLine("Currently, we have these items in stock. Write down the items sku number to begin a purchase "); foreach (Product items in storage) { Console.WriteLine("Item number: {0} - Name: {1} - Price: {2} - Quantity: {3} ", items.Sku, items.ItemName, items.Price, items.Quantity); } Console.Write("Choose a product by item number: "); int userInputsku = Convert.ToInt32(Console.ReadLine()); Product productSearch = storage.Find(x => x.Sku == userInputsku); if (productSearch != null) { foreach (ProductsInOrder items in productsToBuy) { if (items.product.Sku == userInputsku) { Console.WriteLine("You already choosen that product"); Console.ReadKey(); haveProduct = true; } } if (!haveProduct) { Console.WriteLine("Number of found items: {0}, how many would you like to purchase?", productSearch.Quantity); Console.Write("# "); int NoOfPurchaseOrders = Convert.ToInt32(Console.ReadLine()); if (productSearch.Quantity >= NoOfPurchaseOrders && !String.IsNullOrEmpty(NoOfPurchaseOrders.ToString())) { ProductsInOrder newProduct = new ProductsInOrder(productSearch, NoOfPurchaseOrders); productsToBuy.Add(newProduct); productSearch.Quantity = productSearch.Quantity - NoOfPurchaseOrders; Console.WriteLine("Do you want to add a new product - Y/N"); string inputYesOrNo = Console.ReadLine(); if (inputYesOrNo.ToUpper() == "Y") { addItem = true; } else { Order order = new Order(productsToBuy, customerSearch); orderList.Add(order); Console.WriteLine("Congratulations! your order was successfully processed"); Console.ReadKey(); addItem = false; truish = false; } } else { Console.WriteLine("Yo have choosen to many items"); Console.ReadKey(); } } else { Console.WriteLine("If you want to end and add order write END"); string AddOrderEnd = Console.ReadLine(); if (AddOrderEnd.ToUpper() == "END") { Order order = new Order(productsToBuy, customerSearch); orderList.Add(order); Console.WriteLine("Congratulations! your order was successfully processed"); Console.ReadKey(); addItem = false; truish = false; } } } else { Console.WriteLine("That item do not exist!"); Console.ReadKey(); } } catch (FormatException) { Console.WriteLine("Bad Format"); addItem = true; } } while (addItem); } else { Console.WriteLine("That customer do not exist!"); Console.ReadKey(); } } while (truish); }