// GET: Login/Create public ActionResult Register([FromQuery] string CustomerFirstName, string CustomerLastName) { Customer customer = new Customer(CustomerFirstName, CustomerLastName); CustomerViewModel cust1 = repo.AddCustomer(customer); if (cust1 == null) {//this renders the index page again. return(View("error", new ErrorViewModel { errorMsg = $"{CustomerFirstName} {CustomerLastName} was not found. Please try again." })); } return(View("SearchOrOrder", cust1)); }
}//END OF SignInUser() static void Main(string[] args) { bool finished = false; var optionsBuilder = new DbContextOptionsBuilder <Project0Context>(); optionsBuilder.UseSqlServer(config.connectionString); using (var db = new Project0Context(optionsBuilder.Options)) { Customer customer = new Customer(); Order order = new Order(); Location location = new Location(); while (finished.Equals(false)) { /*******************log in or register the user*******************/ string userType; do { Console.WriteLine("Are you a returning user of do you need to register?"); Console.WriteLine("\n\n\tA - Register.\n\tB - Returning User."); userType = Console.ReadLine(); userType = userType.ToUpper(); //to accept upper and lower case letters. } while (!(userType.Equals("A") || userType.Equals("B"))); switch (userType) { case "A": bool custExists = false; while (custExists == false) { customer = RegisterUser(); //register the user custExists = DBRepository.AddCustomer(db, customer); //add the new, VALIDATED, user to the DB. } break; case "B": string custExists2 = null; while (custExists2 == null) { customer = SignInUser(db); //sign the user in. customer = DBRepository.ReadCustomer(db, customer); if (customer != null) { custExists2 = "good"; } } break; } /***************************CHOOSE TO SEARCH OR PLACE AN ORDER***********************/ bool quitter1 = false; do { do { Console.WriteLine("\n Would you like to continue to the ordering process, " + "or would you like to search for things??"); Console.WriteLine("\n\n\tA - Proceed to order.\n\tB - Search."); userType = Console.ReadLine(); userType = userType.ToUpper(); //to accept upper and lower case letters. } while (!(userType.Equals("A") || userType.Equals("B"))); switch (userType) { case "A": Console.WriteLine("\n\t.......Proceeding to the ordering page......."); quitter1 = true; break; case "B": searching.goSearching(db); break; } if (quitter1 == true) { break; } Console.WriteLine("Would you like to START OVER or QUIT?\n\t\tType START OVER or QUIT"); string answer = Console.ReadLine(); answer = answer.ToLower(); if (answer.Equals("start over")) { //continue; } else { quitter1 = true; System.Environment.Exit(0); } } while (quitter1 == false); /**********************choose the location*****/ var allLocations = DBRepository.ReadAllLocations(db);//returns a list of locations string locChoice; int finalLocChoice; do { foreach (var item in allLocations) { Console.WriteLine($"{item.LocationId} - {item.LocationName}\n"); } Console.WriteLine("Please choose a number from the above list."); locChoice = Console.ReadLine(); finalLocChoice = Convert.ToInt32(locChoice); location = DBRepository.ReadLocationById(db, finalLocChoice); } while (location == null); Console.WriteLine($"You chose our {location.LocationName} location. Happy shopping!"); /*************************Make the order****************************/ //int prodChoice; string choice; string choiceQuantity; int choiceQuantityInt; //get all the products in the chosen locations inventory var allProductsInInventory = DBRepository.ReadLocationInventory(db, location.LocationName); var allProducts = DBRepository.ReadAllProducts(db); do { Console.WriteLine("\n\tPlease choose from the available product numbers.\n\tEnter a product number and hit enter." + "\n\tYou may keep placing products until\n\tyou enter 'checkout' to check out."); //display all products from this location. foreach (var item in allProductsInInventory) { int testNum = item.ProductId; Product prod = DBRepository.ReadProductById(db, item.ProductId); //Console.WriteLine($"this is item.ProductID=>{item.ProductId} ... This is testNum=>{testNum} ...this is prod.ProductID=>{prod.ProductID}"); Console.WriteLine($"\t{prod.ProductID} - {prod.ProductName} = {prod.ProductPrice}. {item.ProductQuantity} in stock."); } Console.WriteLine("\tcheckout - Check out."); choice = Console.ReadLine(); choice = choice.ToLower(); if (choice.Equals("checkout")) { continue; } int prodIdChoice; prodIdChoice = Convert.ToInt32(choice); //make sure the name entered is in the list. if (allProductsInInventory.Exists(x => x.ProductId == prodIdChoice) == false) { Console.WriteLine("\n\t\tYour choice is not in the list."); continue; } else { //get the chosen named Product from the Products table. Inventory choice3 = allProductsInInventory.Find(x => x.ProductId.Equals(prodIdChoice)); Product prod = DBRepository.ReadProductById(db, choice3.ProductId); Console.WriteLine($"\nHow Many {prod.ProductName}'s would you like? There are {choice3.ProductQuantity} available"); //Console.WriteLine($"found product => {choice3.ProductName} - {choice3.ProductPrice} - {choice3.ProductQuantity}"); choiceQuantity = Console.ReadLine(); choiceQuantityInt = Convert.ToInt32(choiceQuantity); if (choiceQuantityInt > choice3.ProductQuantity) { Console.WriteLine($"\nThere are not enough {prod.ProductName} available. \nThe maximum you may add is {choice3.ProductQuantity}. Try again.\n"); continue; } else { //check if the item has already been ordered. if not, add it and decrement amount available. if (order.itemsOrdered.ContainsKey(prod.ProductName) == false) { order.itemsOrdered.Add(prod.ProductName, choiceQuantityInt); choice3.ProductQuantity -= choiceQuantityInt;//decrement amount in context } else { //add the previously ordered quantity back to the inventory then subtract the newly ordered amount choice3.ProductQuantity = choice3.ProductQuantity + order.itemsOrdered[prod.ProductName]; order.itemsOrdered[prod.ProductName] = choiceQuantityInt; choice3.ProductQuantity = choice3.ProductQuantity - choiceQuantityInt;//decrement amount in context Console.WriteLine($"\n\tYour desired amount of {prod.ProductName} has been updated to {order.itemsOrdered[prod.ProductName]}"); } } } //print current state of customers order Console.WriteLine("\nYou current order is... "); foreach (var item in order.itemsOrdered) { Console.WriteLine($"=== {item.Key} === {item.Value}="); } } while (!choice.Equals("checkout"));//end of ordering loop order.LocationID = location.locID; order.CustomerID = customer.CustID; DBRepository.AddOrder(db, order); db.SaveChanges(); finished = true; } //END OF WHILE LOOP Console.WriteLine("\n\n\t============= Thank You for shopping with us. =============\n"); } //END OF USING } //END OF MAIN