static Customer LogIn(IProject0Repository projectRepository) { var customer = new Customer(); var customerList = projectRepository.GetCustomers(); while (customer.FirstName == null) { _io.Output("Enter your firstName: "); string firstName = _io.Input(); _io.Output("Enter your lastName: "); string lastName = _io.Input(); try { var test = customerList.First(c => c.FirstName.ToLower() == firstName && c.LastName.ToLower() == lastName); customer = test; } catch (ArgumentException ex) { _io.Output("Your name does not match our database."); s_logger.Info(ex); Console.WriteLine(ex.Message); } } return(customer); }
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(); }
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"); }
/// <summary> /// Write a list of products to console with optional search-by-name. /// </summary> public static void DisplayProducts(IProject0Repository repository) { Console.Write(" Enter a product name to search for? (Y/N) : "); string doSearch = Console.ReadLine().ToLower(); string search = null; if (doSearch == "y" || doSearch == "yes") { Console.Write(" "); search = Console.ReadLine(); } Console.WriteLine(); IEnumerable <IProduct> products = repository.GetProducts(search); foreach (IProduct p in products) { Console.WriteLine(p.Name + " " + p.BestBy + " " + p.UnitPrice); } Console.WriteLine(); Console.Write(" Press Enter to continue"); Console.ReadLine(); Console.WriteLine(); }
/// <summary> /// Write a list of customers to console with optional search-by-name. /// </summary> public static void DisplayCustomers(IProject0Repository repository) { Console.Write(" Enter a customer name to search for? (Y/N) : "); string doSearch = Console.ReadLine().ToLower(); string search = null; if (doSearch == "y" || doSearch == "yes") { Console.Write(" "); search = Console.ReadLine(); } Console.WriteLine(); IEnumerable <ICustomer> result = repository.GetCustomers(search); foreach (ICustomer c in result) { Console.WriteLine(c.FirstName + " " + c.LastName + " ; " + c.Address + ", " + c.City + " " + c.State + ", " + c.Country + " " + c.PostalCode + " ; " + c.Phone + " ; " + c.Email); } Console.WriteLine(); Console.Write(" Press Enter to continue"); Console.ReadLine(); Console.WriteLine(); }
public static void Main(string[] args) { using var dependencies = new Dependencies(); IProject0Repository repository = dependencies.CreateRepository(); MainMenu(repository); }
public static void Main() { using var dependencies = new Dependencies(); IProject0Repository repository = dependencies.CreateRepository(); RunUI(repository); }
//static async Task Main(string[] args) static void Main(string[] args) { var dependencies = new Dependencies(); using IProject0Repository projectRepository = dependencies. CreateProject0Repository(); _io.Output("Welcome to the latest in Food Delivery! \n"); bool loopBool = true; while (loopBool) { _io.Output("Would you like to place an order? (order)\n"); _io.Output("Add a new customer? (new)\n"); _io.Output("Display a specific order? (specific)\n"); _io.Output("Display all order history of a store location? (location)\n"); _io.Output("Display all order history of a customer? (customer)\n"); _io.Output("Quit? (quit)\n"); string input = _io.Input().ToLower(); if (input == "order") { var customer = LogIn(projectRepository); MakeOrder(customer, projectRepository); } else if (input == "new") { NewUser(projectRepository); } else if (input == "specific") { DisplaySpecificOrder(projectRepository); } else if (input == "location") { DisplayLocationHistory(projectRepository); } else if (input == "customer") { DisplayCustomerHistory(projectRepository); } else if (input == "quit") { loopBool = false; } else { _io.Output("Invalid Input. \n"); //invalid input //repeat } } }
public static void MainMenu(IProject0Repository repository) { while (true) { Console.WriteLine("c: Customer Menu."); Console.WriteLine("o: Order Menu."); Console.WriteLine("l: Store Menu."); Console.WriteLine("p: Product Menu."); Console.WriteLine("s: Save Data."); Console.WriteLine("q: Quit Program"); Console.WriteLine(); string userinput = Console.ReadLine(); Console.WriteLine(); if (userinput == "c") { CustomerUI.DisplayOptions(repository); } else if (userinput == "p") { ProductUI.DisplayOptions(repository); } else if (userinput == "o") { OrderUI.DisplayOptions(repository); } else if (userinput == "l") { StoreUI.DisplayOptions(repository); } else if (userinput == "s") { if (repository.SaveChanges()) { Console.WriteLine("--Successfully Saved Data to Database!\n"); } else { Console.WriteLine("Something went wrong"); } } else if (userinput == "q") { break; } } }
/// <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(); }
public static void DisplayOptions(IProject0Repository repository) { while (true) { Console.WriteLine("You are now viewing the Product Management Menu."); Console.WriteLine(); Console.WriteLine("c: To Create A New Product"); Console.WriteLine("q: To Return Back to the Main Menu"); Console.WriteLine(); string userinput = Console.ReadLine().ToLower(); if (userinput == "c") { Console.WriteLine("Please Enter The Products Name\n"); string productname = Console.ReadLine(); decimal price; while (true) { Console.WriteLine("Please Enter The Products Price\n"); string pricestring = Console.ReadLine(); if (decimal.TryParse(pricestring, out price)) { break; } } } else if (userinput == "q") { Console.WriteLine(); Console.WriteLine("Returning to Main Menu\n"); break; } } }
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"); } }
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"); } }
/// <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(); }
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."); }
public static void RunUI(IProject0Repository repository) { // "Lani", "Becker", "1805 Highrise Road", "Mythopolis", null, "Hypothetican Republic", null, null, "*****@*****.**" Console.WriteLine(); Console.WriteLine(" Golly G General Stores Master Control Program "); Console.WriteLine(" Welcome, Authorized User!"); Console.WriteLine(); // Display main menu bool exit = false; do { Console.WriteLine(" (1) Display Customers"); Console.WriteLine(" (2) Add Customer"); Console.WriteLine(" (3) Display Products"); Console.WriteLine(" (4) Display Orders"); Console.WriteLine(" (5) Add Order"); Console.WriteLine(" (6) Exit Program"); Console.WriteLine(); int selection = -1; do { Console.Write(" Enter a menu selection by number: "); if (Int32.TryParse(Console.ReadLine(), out selection)) { if (selection < 1 || selection > 6) { Console.WriteLine(" Selection invalid."); } } else { Console.WriteLine(" Selection could not be parsed. Please enter a number between 1 and 6"); selection = -1; } } while (selection < 1 || selection > 6); switch (selection) { case 1: DisplayCustomers(repository); break; case 2: AddCustomer(repository); break; case 3: DisplayProducts(repository); break; case 4: DisplayOrders(repository); break; case 5: AddOrder(repository); break; case 6: exit = true; break; default: throw new ArgumentException(); } } while (exit == false); }
/// <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(); }
public static void DisplayOptions(IProject0Repository repository) { while (true) { Console.WriteLine("You are now viewing the Store Location Management Menu"); Console.WriteLine(); Console.WriteLine("h: View a Store Location's Order History"); Console.WriteLine("c: Create a Store Location"); Console.WriteLine("q: To Return Back to the Main Menu"); Console.WriteLine(); string userinput = Console.ReadLine(); if (userinput == "c") { Console.WriteLine("Please Enter The Store Locations City\n"); string city = Console.ReadLine(); Console.WriteLine("Please Enter Its State\n"); string state = Console.ReadLine(); Console.WriteLine("Please Enter The Address\n"); string address = Console.ReadLine(); Console.WriteLine("Please Enter The Locations Phone Number\n"); string phoneNumber = Console.ReadLine(); try { Project.Library.StoreLocation storeLocation = new Project.Library.StoreLocation(city, state, address, phoneNumber); if (repository.AddStoreLocation(storeLocation)) { Console.WriteLine("Successfully added Store Location"); Console.WriteLine("Remember to save to lock in changes."); } } catch (ArgumentException exception) { Console.WriteLine("Could not Create Store Location"); Console.WriteLine(exception.Message); } } else if (userinput == "h") { Console.WriteLine(); Console.WriteLine("Please enter the id of the store whose order history you'd like to view.\n"); int storeid; while (true) { string storeidstring = Console.ReadLine(); if (int.TryParse(storeidstring, out storeid)) { break; } Console.WriteLine("Value must be an integer"); } var orders = repository.GetOrderByStoreId(storeid); int count = orders.Count; Console.WriteLine($"\nWe found {count} results for this store\n"); if (count > 0) { foreach (var order in orders) { Console.WriteLine($"Order Id:{order.OrderID} Customer with Id:{order.CustomerID} took an order here at {order.OrderTime}\n"); } } ; } else if (userinput == "q") { Console.WriteLine(); Console.WriteLine("Returning to Main Menu\n"); break; } } }
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; } } }
public static void DisplayOptions(IProject0Repository repository) { while (true) { Console.WriteLine("c: To Create A New Customer"); Console.WriteLine("s: To Search A Customer By Name"); Console.WriteLine("h: Display Customer history"); Console.WriteLine("q: To Return Back to the Main Menu"); Console.WriteLine(); string userinput = Console.ReadLine().ToLower(); if (userinput == "c") { Console.WriteLine("Please Enter The Customer First Name\n"); string firstname = Console.ReadLine(); Console.WriteLine("Please Enter The Customer Last Name\n"); string lastname = Console.ReadLine(); try { Project.Library.Customer customer = new Project.Library.Customer(firstname, lastname); repository.AddCustomer(customer); if (repository.AddCustomer(customer)) { Console.WriteLine("Successfully added Customer"); Console.WriteLine("Remember to save to lock in changes."); } } catch (ArgumentException exception) { Console.WriteLine("Could not Create Customer"); Console.WriteLine(exception.Message); } } else if (userinput == "s") { Console.WriteLine(); Console.WriteLine("Enter a First or Last Name you would like to search for.\n"); Console.WriteLine("First Name:"); string searchfirstname = Console.ReadLine(); var customers = repository.SearchCustomer(searchfirstname); Console.WriteLine($"ID:{customers.CustomerID} {customers.FirstName},{customers.LastName}"); } else if (userinput == "h") { Console.WriteLine(); Console.WriteLine("Please enter the id of the customer whose order history you'd like to view.\n"); int customerid; while (true) { string customeridstring = Console.ReadLine(); if (int.TryParse(customeridstring, out customerid)) { break; } Console.WriteLine("Value must be an integer"); } var orders = repository.GetOrderByCustomerId(customerid); var customer = repository.FindCustomerID(customerid); int count = orders.Count; Console.WriteLine($"\nWe found {count} results for you from {customer.FirstName}, {customer.LastName}\n"); if (count > 0) { foreach (var order in orders) { Console.WriteLine($"Order Id:{order.OrderID} -- Customer with Id:{order.CustomerID} took an order from store with Id:{order.StoreID} at {order.OrderTime}\n"); } } ; } else if (userinput == "q") { Console.WriteLine(); Console.WriteLine("Returning to Main Menu\n"); break; } } }