public static List <TShirt> GenerateTShirts(int number) { var tshirts = new List <TShirt>(); while (tshirts.Count <= number) { bool exists = false; var color = (ColorEnum)(random.Next(0, 7)); var size = (SizeEnum)(random.Next(0, 7)); var fabric = (FabricEnum)(random.Next(0, 7)); var tshirt = new TShirt { Color = color, Size = size, Fabric = fabric }; tshirt.SetPricingStrategy(new PriceTag(tshirt)); tshirt.GetPriceTag(); if (number <= 300) { foreach (var shirt in tshirts) { if (tshirt.Color == shirt.Color && tshirt.Size == shirt.Size && tshirt.Fabric == shirt.Fabric) { exists = true; } } if (!exists) { tshirts.Add(tshirt); } } else { tshirts.Add(tshirt); } } return(tshirts); }
private static void CreateMenu() { var userChoice = 0; var colors = Enum.GetNames(typeof(ColorEnum)).ToList(); var sizes = Enum.GetNames(typeof(SizeEnum)).ToList(); var fabrics = Enum.GetNames(typeof(FabricEnum)).ToList(); var newTshirt = new TShirt(); Console.WriteLine("\nColors"); for (int i = 0; i < colors.Count; i++) { //Console.Write($"{(int)(ColorEnum)i + 1}. "); Console.Write($"{i + 1}. "); Console.WriteLine(colors[i]); } Console.Write("Choose color: "); try { userChoice = int.Parse(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("\nNon valid choice! Try again...\n"); return; } if (userChoice <= 0 || userChoice > colors.Count) { Console.WriteLine("\nNo such choice! Try again...\n"); return; } newTshirt.Color = (ColorEnum)(userChoice - 1); Console.WriteLine("\nSizes"); for (int i = 0; i < sizes.Count; i++) { Console.Write($"{i + 1}. "); Console.WriteLine(sizes[i]); } Console.Write("Choose Size: "); try { userChoice = int.Parse(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("\nNon valid choice! Try again...\n"); return; } if (userChoice <= 0 || userChoice > sizes.Count) { Console.WriteLine("\nNo such choice! Try again...\n"); return; } newTshirt.Size = (SizeEnum)(userChoice - 1); Console.WriteLine("\nFabrics"); for (int i = 0; i < sizes.Count; i++) { Console.Write($"{i + 1}. "); Console.WriteLine(fabrics[i]); } Console.Write("Choose Fabric: "); try { userChoice = int.Parse(Console.ReadLine()); } catch (FormatException) { Console.WriteLine("\nNon valid choice! Try again...\n"); return; } if (userChoice <= 0 || userChoice > fabrics.Count) { Console.WriteLine("\nNo such choice! Try again...\n"); return; } newTshirt.Fabric = (FabricEnum)(userChoice - 1); newTshirt.SetPricingStrategy(new PriceTag(tshirt)); newTshirt.GetPriceTag(); Console.WriteLine("\nYour Choice:"); PrintOut.PrintOutSingle(newTshirt); tshirt = newTshirt; AddToBasket(null); }