public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driver = driverRepository.GetByName(driverName);
            ICar    car    = carRepository.GetByName(carModel);

            driver.AddCar(car);
            return(String.Format(OutputMessages.CarAdded, driverName, carModel));
        }
        public string AddCarToDriver(string driverName, string carModel)
        {
            ICar    car    = CarRepository.Colection.FirstOrDefault(el => el.Model == carModel);
            IDriver driver = DriverRepository.Colection.FirstOrDefault(el => el.Name == driverName);

            if (driver == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName));
            }
            if (car == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.CarNotFound, carModel));
            }
            driver.AddCar(car);
            return(string.Format(OutputMessages.CarAdded, driverName, carModel));
        }
Example #3
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver currentDriver = driveRep.GetByName(driverName);
            ICar    currentCar    = carRep.GetByName(carModel);

            if (currentDriver == null)
            {
                throw new InvalidOperationException($"Driver {driverName} could not be found.");
            }
            if (currentCar == null)
            {
                throw new InvalidOperationException($"Car {carModel} could not be found.");
            }
            currentDriver.AddCar(currentCar);
            return($"Driver {driverName} received car {carModel}.");
        }
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driver = driverRepository.GetByName(driverName);
            ICar    car    = carsRepository.GetByName(carModel);

            if (driver == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName));
            }
            if (car == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.CarNotFound, carModel));
            }

            driver.AddCar(car);
            return(string.Format(OutputMessages.CarAdded, driverName, carModel));
        }
        public string AddCarToDriver(string driverName, string carModel)
        {
            if (this.driverRepository.GetByName(driverName) == null)
            {
                throw new InvalidOperationException($"Driver {driverName} could not be found.");
            }

            if (this.carRepository.GetByName(carModel) == null)
            {
                throw new InvalidOperationException($"Car {carModel} could not be found.");
            }

            ICar    car    = this.carRepository.GetByName(carModel);
            IDriver driver = this.driverRepository.GetByName(driverName);

            driver.AddCar(car);

            return(string.Format(OutputMessages.CarAdded, driverName, carModel));
        }
Example #6
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            if (!driverRepository.Models.Any(d => d.Name == driverName))
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName));
            }

            if (!carRepository.Models.Any(c => c.Model == carModel))
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.CarNotFound, carModel));
            }

            IDriver targetDriver = driverRepository.GetByName(driverName);
            ICar    targetCar    = carRepository.GetByName(carModel);

            targetDriver.AddCar(targetCar);

            return($"{string.Format(OutputMessages.CarAdded, driverName, carModel)}");
        }
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driver = this.driverRepo.GetByName(driverName);
            ICar    car    = this.carRepo.GetByName(carModel);

            if (driver == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.DriverNotFound, driverName));
            }

            if (car == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.CarNotFound, carModel));
            }

            driver.AddCar(car);
            this.carRepo.Remove(car);  // Not necesssry
            return(string.Format(OutputMessages.CarAdded, driverName, carModel));
        }
Example #8
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            ICar    car    = this.cars.GetByName(carModel);
            IDriver driver = this.drivers.GetByName(driverName);

            if (driver == null)
            {
                throw new InvalidOperationException($"Driver {driverName} could not be found.");
            }
            else if (car == null)
            {
                throw new InvalidOperationException($"Car {carModel} could not be found.");
            }
            else
            {
                driver.AddCar(car);
                return($"Driver {driver.Name} received car {car.Model}.");
            }
        }
Example #9
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driver = this.drivers.GetByName(driverName);
            ICar    car    = this.cars.GetByName(carModel);

            if (driver == null)
            {
                string msg1 = String.Format(ExceptionMessages.DriverNotFound, driverName);
                throw new InvalidOperationException(msg1);
            }
            if (car == null)
            {
                string msg1 = String.Format(ExceptionMessages.CarNotFound, carModel);
                throw new InvalidOperationException(msg1);
            }
            driver.AddCar(car);
            string msg = String.Format(OutputMessages.CarAdded, driverName, carModel);

            return(msg);
        }
Example #10
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driverFromRepository = driverRepository.GetAll().FirstOrDefault(x => x.Name == driverName);

            if (driverFromRepository == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.DriverNotFound, driverName));
            }

            ICar carFromRepository = carsRepository.GetAll().FirstOrDefault(x => x.Model == carModel);

            if (carFromRepository == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.CarNotFound, carModel));
            }

            driverFromRepository.AddCar(carFromRepository);

            return(String.Format(OutputMessages.CarAdded, driverName, carModel));
        }
Example #11
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            if (!drivers.Any(x => x.Name == driverName))
            {
                string exeption = string.Format(ExceptionMessages.DriverNotFound, driverName);
                throw new InvalidOperationException(exeption);
            }

            if (!cars.Any(x => x.Model == carModel))
            {
                string exeption = string.Format(ExceptionMessages.CarNotFound, carModel);
                throw new InvalidOperationException(exeption);
            }

            IDriver driver = this.drivers.FirstOrDefault(x => x.Name == driverName);
            ICar    car    = this.cars.FirstOrDefault(x => x.Model == carModel);

            driver.AddCar(car);

            return(string.Format(OutputMessages.CarAdded, driverName, carModel));
        }
        public string AddCarToDriver(string driverName, string carModel)
        {
            if (!this.driverRepository.GetAll().Any(d => d.Name == driverName))
            {
                string excMsg = string.Format(ExceptionMessages.DriverNotFound, driverName);
                throw new InvalidOperationException(excMsg);
            }
            if (!this.carRepository.GetAll().Any(c => c.Model == carModel))
            {
                string msg = string.Format(ExceptionMessages.CarNotFound, carModel);
                throw new InvalidOperationException(msg);
            }

            IDriver driver = this.driverRepository.GetAll().FirstOrDefault(d => d.Name == driverName);
            ICar    car    = this.carRepository.GetAll().FirstOrDefault(c => c.Model == carModel);

            driver.AddCar(car);
            string outputMsg = string.Format(OutputMessages.CarAdded, driverName, carModel);

            return(outputMsg);
        }
Example #13
0
        public string AddCarToDriver(string driverName, string carModel)
        {
            IDriver driver = drivers.GetAll().FirstOrDefault(x => x.Name == driverName);
            ICar    car    = cars.GetAll().FirstOrDefault(x => x.Model == carModel);

            if (driver == null)
            {
                string msg = string.Format(ExceptionMessages.DriverNotFound, driverName);
                throw new InvalidOperationException(msg);
            }

            if (car == null)
            {
                string msg = string.Format(ExceptionMessages.CarNotFound, carModel);
                throw new InvalidOperationException(msg);
            }

            driver.AddCar(car);
            string outputMsg = string.Format(OutputMessages.CarAdded, driverName, carModel);

            return(outputMsg);
        }