private static PersonalComputer ConfigurePersonalComputer(ComponentFactory componentFactory, ProductFactory productFactory) { string answer; PersonalComputer personalComputer; PCTower pcTower = ConfigurePCTower(componentFactory, productFactory); if (!pcTower.IsValidProduct()) { return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } PCScreen pcScreen = ConfigurePCScreen(productFactory); if (!pcScreen.IsValidProduct()) { return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } Console.WriteLine("Set the size of the Hard Disk\n"); answer = Console.ReadLine(); HardDrive hardDrive = componentFactory.CreateComponent("HardDrive") as HardDrive; if (!hardDrive.SetValue(answer)) { WrongInput(); return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } personalComputer = productFactory.CreateProduct("PersonalComputer") as PersonalComputer; if (!personalComputer.SetScreen(pcScreen)) { WrongInput(); return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } if (!personalComputer.SetPCTower(pcTower)) { WrongInput(); return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } ; if (!personalComputer.SetHardDrive(hardDrive)) { WrongInput(); return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } if (!personalComputer.IsValidProduct()) { return(productFactory.CreateProduct("PersonalComputer") as PersonalComputer); } return(personalComputer); }
static void Main(string[] args) { ComponentFactory componentFactory = new ComponentFactory(); ProductFactory productFactory = new ProductFactory(); SoftwareTypes softwareTypes = new SoftwareTypes(); bool exit = false; while (!exit) { Console.WriteLine("Welcome to Our E-shop"); Console.WriteLine("What would you like to buy ?\n " + "press 'a' for PC tower\n" + "press 'b' for a PC screen\n" + "press 'c' for a Personal Computer\n" + "press 'd' for a Workstation\n" + "press 'e' to exit\n"); string answer = Console.ReadLine(); if (answer.Equals("a")) { PCTower pcTower = ConfigurePCTower(componentFactory, productFactory); if (!pcTower.IsValidProduct()) { CannotFinishTheOrder(); continue; } PrintReceiptInfo(pcTower); } else if (answer.Equals("b")) { PCScreen pcScreen = ConfigurePCScreen(productFactory); if (!pcScreen.IsValidProduct()) { CannotFinishTheOrder(); continue; } PrintReceiptInfo(pcScreen); } else if (answer.Equals("c")) { PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory); if (!personalComputer.IsValidProduct()) { CannotFinishTheOrder(); continue; } PrintReceiptInfo(personalComputer); } else if (answer.Equals("d")) { PersonalComputer personalComputer = ConfigurePersonalComputer(componentFactory, productFactory); if (!personalComputer.IsValidProduct()) { CannotFinishTheOrder(); continue; } Console.WriteLine("Please select one of the available softwares\n"); foreach (var type in softwareTypes.Types) { Console.WriteLine(type.Value + "\n"); } answer = Console.ReadLine(); Software software = componentFactory.CreateComponent("Software") as Software; if (!software.SetValue(answer)) { WrongInput(); continue; } Workstation workstation = productFactory.CreateProduct("Workstation") as Workstation; if (!workstation.SetPersonalComputer(personalComputer) || !workstation.SetSoftware(software)) { continue; } if (!workstation.IsValidProduct()) { CannotFinishTheOrder(); continue; } PrintReceiptInfo(workstation); } else if (answer.Equals("e")) { exit = true; } else { WrongInput(); } } }