public static void OrderProduct(User user) { Message.Print("To order a product, first type in the vendor name form the list:", ConsoleColor.DarkCyan); VendorsRepository.GetVendorsNames(); string vendorName = ReadLine(); string vendorNameKey = VendorsRepository.VendorsAndProducts.Where(kvp => kvp.Key.ToLower().Contains(vendorName.ToLower())).FirstOrDefault().Key; if (!string.IsNullOrEmpty(vendorNameKey) && !string.IsNullOrEmpty(vendorName)) { UserInputServices.GetVendorsProducts(vendorName); } else { Message.Print("Please try again and enter the vendor name correctly.", ConsoleColor.DarkRed); OrderProduct(user); } Message.Print("Now, type in the number of the product and its quantity, separated by a space:", ConsoleColor.DarkCyan); string[] orderString = ReadLine().Split(); List <Product> vendorsProducts = UserInputServices.GetVendorsProductsAsList(vendorName); if (orderString.Length == 2 && Int32.TryParse(orderString[0], out int productNumber) && productNumber > 0 && productNumber <= vendorsProducts.Count && Int32.TryParse(orderString[1], out int productQuantity) && productQuantity > 0) { Product product = vendorsProducts[productNumber - 1]; Order order = new Order(product.ProductName, productQuantity, product.ProductPrice); user.AddToShoppingCart(order); Message.Print($"Successfully created order for {productQuantity} {product.ProductName}((e)s), totaling {(productQuantity * product.ProductPrice).PrintFormattedMKDPrice()}", ConsoleColor.DarkGreen); } else { Message.Print("Please try again and correctly input the necessary information.", ConsoleColor.DarkRed); } }
public static void SearchProductCatalog() { VendorsRepository.GetAllProducts(); Message.Print("This is the list of vendors, for your convenience:", ConsoleColor.Yellow); VendorsRepository.GetVendorsNames(); WriteLine("In order to search the product catalog, please follow these instructions:\n\n- to search by vendor name input V and to search by product name input P,\n- then input the vendor name (just the first word of the name) or the product name or name of a part (just one word),\n- to view the products sorted by name input N or to view them sorted by price input P,\n- to view them in ascending order input A and to view them in descending order input D.\n\nExample search input:\n\nV bakery P A"); Message.Print("Enter your input:", ConsoleColor.DarkCyan); string userSearchInput = ReadLine(); string[] searchParameters = userSearchInput.Split(' '); if (searchParameters.Length == 4) { UserInputServices.GetProductsBySearchInput(searchParameters); } else { Message.Print("Please try again and input the information correctly.", ConsoleColor.DarkRed); } }