public bool BuyProduct(int counter, int number, List <Module> modules, List <Part> cartP, List <Module> cartM, List <Configuration> cartC) { while (true) { Console.WriteLine("Choose Part to Buy:"); int input = int.Parse(Console.ReadLine()); if (input < 1 || input > counter) { Console.WriteLine("Please enter valid number of product. Please press any key and try again!"); Console.ReadLine(); continue; } else { List <Module> selectedParts = new List <Module>(); foreach (var item in modules) { if ((int)item.Type == number) { selectedParts.Add(item); } } int brojce = UiService.HowMany(); for (int i = 0; i < brojce; i++) { cartM.Add(selectedParts[input - 1]); } Module boughtPart = selectedParts[input - 1]; Console.WriteLine($"Product of type: {boughtPart.Type} is added to your cart! Quantity: {brojce}"); var nesto = UiService.NextAction(ShowByTypeModules, modules, cartP, cartM, cartC); return(nesto); } } }
public bool ShowProductsByPart(List <Part> parts, List <Part> cartP, List <Module> cartM, List <Configuration> cartC) { while (true) { Console.Clear(); int counter = 1; foreach (var part in parts) { Console.WriteLine($"{counter}. Name: {part.Name}"); counter++; } Console.WriteLine("Choose product to buy:"); int input = int.Parse(Console.ReadLine()); if (input < 1 || input > counter) { Console.WriteLine("Enter valid number. Press any key and try again!"); Console.ReadLine(); continue; } else { int brojce = UiService.HowMany(); for (int i = 0; i < brojce; i++) { cartP.Add(parts[input - 1]); } Part boughtPart = parts[input - 1]; Console.WriteLine($"Product of type: {boughtPart.Type} {boughtPart.Name} is added to your cart! Quantity: {brojce}"); var nesto = UiService.NextAction(ShowProductsByPart, parts, cartP, cartM, cartC); return(nesto); } } }
public bool ShowByPriceOfModules(List <Module> modules, List <Part> cartP, List <Module> cartM, List <Configuration> cartC) { while (true) { int min = 0; int max = 0; while (true) { Console.Clear(); Console.WriteLine("Lowest is 100 dollars, Highest is 840. Enter between these numbers:"); Console.WriteLine("Enter minimum price of Module:"); min = int.Parse(Console.ReadLine()); if (min < 100 || min > 840) { Console.WriteLine("Enter valid number.Press any key."); Console.ReadLine(); continue; } else { break; } } while (true) { Console.Clear(); Console.WriteLine("Enter maximum price of Part:"); max = int.Parse(Console.ReadLine()); if (max < min || max > 840) { Console.WriteLine("Enter valid number.Press any key."); Console.ReadLine(); continue; } else { break; } } var itemList = modules.Where(x => x.Price > min && x.Price < max).ToList(); if (itemList.Count == 0) { Console.WriteLine("There are no parts in that range! Please try again.Press any key."); Console.ReadLine(); continue; } Console.Clear(); int counter = 1; foreach (var item in itemList) { Console.WriteLine($"{counter}. Name: {item.Type}, Price: {item.Price}"); counter++; } Console.WriteLine("Choose Product to buy:"); int input = int.Parse(Console.ReadLine()); if (input < 1 || input > counter) { Console.WriteLine("Enter valid number. Press any key and try again!"); Console.ReadLine(); continue; } else { var brojce = UiService.HowMany(); for (int i = 0; i < brojce; i++) { cartM.Add(itemList[input - 1]); } Module boughtPart = itemList[input - 1]; Console.WriteLine($"Product of type: {boughtPart.Type} is added to your cart! Quantity: {brojce}"); var nesto = UiService.NextAction(ShowByPriceOfModules, modules, cartP, cartM, cartC); return(nesto); } } }