public void ExecuteThisCommand(string[] commandParameters) { this.coreValidator.EitherOrParameterLength(commandParameters, 5, 7); var employeeFirstName = commandParameters[1]; var clientUniqueName = commandParameters[2]; var vehicleRegistrationNumber = commandParameters[3]; var stockUniqueNumber = commandParameters[4]; var employeeLastName = ""; string employeeDepartmentName = ""; IEmployee employee; if (commandParameters.Length == 7) { employeeLastName = commandParameters[5]; employeeDepartmentName = commandParameters[6]; employee = this.coreValidator.EmployeeUnique(database.Employees, employeeFirstName, employeeLastName, employeeDepartmentName); } else { employee = this.coreValidator.EmployeeUnique(database.Employees, employeeFirstName, null, null); } this.coreValidator.CounterpartyNotRegistered(database.Clients, clientUniqueName, "client"); var client = database.Clients.FirstOrDefault(x => x.Name == clientUniqueName); //stock we sell must be present in the warehouse bool stockExists = stockManager.ConfirmStockExists(stockUniqueNumber, employee); if (stockExists == false) { throw new ArgumentException( $"Trying to sell the stock with unique ID {stockUniqueNumber} that is not present in the Warehouse"); } var stock = this.database.AvailableStocks.FirstOrDefault(x => x.UniqueNumber == stockUniqueNumber); //there is no need to check vehicle for null because we create a default vehicle with every client registration var vehicle = ((IClient)client).Vehicles.FirstOrDefault(x => x.RegistrationNumber == vehicleRegistrationNumber); this.SellStockToClient(stock, (IClient)client, vehicle); }