public void Mediate(ICommand command, IClient buyer, IClient seller, ICar car) { if (!CheckForValidity(buyer, seller, car)) { return; } seller.RemoveCar(car); car.Owner = buyer; buyer.AddCar(car, commission: commission); Budget += commission; ledger.Add(command); Console.WriteLine($"\n-------- COMMAND IN PROGRESS --------"); Console.WriteLine($"The selling of the car {car.Name} come true, successfully!"); Console.WriteLine($"By the mediator with commission of {commission} and budget {Budget}, \n" + $"Seller {seller.Name} with remaining budget of {seller.Budget}. \n" + $"Buyer {buyer.Name} with remaining budget of {buyer.Budget}. \n\n" + $"Updated cars of the seller {seller.Name} : "); seller.OwnedCars.ForEach(x => Console.WriteLine(x.Name)); Console.WriteLine($"Updated cars of the buyer {buyer.Name}: "); buyer.OwnedCars.ForEach(x => Console.WriteLine(x.Name)); Console.WriteLine($"Updated cars of the mediator {Name} : "); buyer.OwnedCars.ForEach(x => Console.WriteLine(x.Name)); Console.WriteLine($"-------- COMMAND PROGRESS DONE--------\n"); }
static void Main(string[] args) { ICommand command; IMediator mediator = new Mediator(5000, 5000, "Hitler"); IClient firstClient = new Client("Ahmet", 90000); IClient secondClient = new Client("Mehmet", 100000); IClient thirdClient = (IClient)mediator; ICar audi = new Car(secondClient, 10000, "Audi"); secondClient.AddCar(audi, true); ICar bmw = new Car(thirdClient, 5000, "BMW"); thirdClient.AddCar(bmw, true); command = new BuyCommand(audi, firstClient, secondClient, mediator); command.Execute(); command.Unexecute(); System.Console.ReadKey(); }