コード例 #1
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider rider = this.riderRepository
                           .GetByName(riderName);

            if (rider == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RiderNotFound,
                              riderName));
            }

            IMotorcycle motorcycle = this.motoRepository
                                     .GetByName(motorcycleModel);

            if (motorcycle == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.MotorcycleNotFound,
                              motorcycleModel));
            }

            rider.AddMotorcycle(motorcycle);

            return(string.Format(
                       OutputMessages.MotorcycleAdded,
                       riderName,
                       motorcycleModel));
        }
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = CheckIfRiderExists(riderName);
            IMotorcycle motorcycle = CheckIfMotorExists(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return(string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel));
        }
コード例 #3
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riders.GetByName(riderName);
            IMotorcycle motorcycle = motorcycles.GetByName(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return(string.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model));
        }
コード例 #4
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.GetByName(riderName);
            IMotorcycle motorcycle = motorcycleRepository.GetByName(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return($"{string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel)}");
        }
コード例 #5
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.Models.FirstOrDefault(r => r.Name == riderName);
            IMotorcycle motorcycle = this.motorcycleRepository.Models.FirstOrDefault(m => m.Model == motorcycleModel);

            if (rider == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, riderName));
            }
            if (motorcycle == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.MotorcycleNotFound, motorcycleModel));
            }
            rider.AddMotorcycle(motorcycle);
            return(String.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model));
        }
コード例 #6
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IMotorcycle targetMotor = motorcycleRepo.GetByName(motorcycleModel);
            IRider      targetRider = riderRepo.GetByName(riderName);

            if (targetRider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            if (targetMotor == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel} could not be found.");
            }
            targetRider.AddMotorcycle(targetMotor);
            return($"Rider {targetRider.Name} received motorcycle {targetMotor.Model}.");
        }
コード例 #7
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.Riders.FirstOrDefault(x => x.Name == riderName);
            IMotorcycle motorcycle = motorcycleRepository.GetByName(motorcycleModel);

            if (rider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            else if (motorcycle == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel } could not be found.");
            }

            rider.AddMotorcycle(motorcycle);
            return($"Rider {riderName} received motorcycle {motorcycleModel}.");
        }
コード例 #8
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            if (this.riderRepository.GetByName(riderName) == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            if (this.motorcycleRepository.GetByName(motorcycleModel) == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel} could not be found.");
            }
            IRider      rider      = this.riderRepository.GetByName(riderName);
            IMotorcycle motorcycle = this.motorcycleRepository.GetByName(motorcycleModel);

            rider.AddMotorcycle(motorcycle);
            this.motorcycleRepository.Remove(motorcycle);

            return($"Rider {riderName} received motorcycle {motorcycleModel}.");
        }
コード例 #9
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            if (riders.GetAll().All(r => r.Name != riderName))
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, riderName));
            }

            if (motorcycles.GetAll().All(m => m.Model != motorcycleModel))
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.MotorcycleNotFound, motorcycleModel));
            }

            IRider      rider = riders.GetAll().First(r => r.Name == riderName);
            IMotorcycle mot   = motorcycles.GetAll().First(m => m.Model == motorcycleModel);

            rider.AddMotorcycle(mot);

            return(String.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel));
        }
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IMotorcycle motorcycle = this.motorcycles.GetByName(motorcycleModel);
            IRider      rider      = this.riders.GetByName(riderName);

            if (rider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            else if (motorcycle == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel} could not be found.");
            }
            else
            {
                rider.AddMotorcycle(motorcycle);
                return($"Rider {rider.Name} received motorcycle {motorcycle.Model}.");
            }
        }
コード例 #11
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            //Gives the motorcycle with given name to the rider with given name (if exists).

            IRider rider = this.riderRepository
                           .GetByName(riderName);

            //If the rider does not exist in rider repository, throw InvalidOperationException with message
            //•	"Rider {name} could not be found."

            if (rider == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RiderNotFound,
                              riderName));
            }

            //If the motorcycle does not exist in motorcycle repository, throw InvalidOperationException with message
            //•	"Motorcycle {name} could not be found."
            IMotorcycle motorcycle = this.motorcycleRepository
                                     .GetByName(motorcycleModel);

            if (motorcycle == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.MotorcycleNotFound,
                              motorcycleModel));
            }

            //If everything is successful you should add the motorcycle to the rider and return the following message:

            rider.AddMotorcycle(motorcycle);

            string result = string.Format(
                OutputMessages.MotorcycleAdded,
                riderName,
                motorcycleModel);

            return(result);
        }
コード例 #12
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            bool isExistRider = this.riderRepository
                                .GetAll()
                                .Any(r => r.Name == riderName);

            if (!isExistRider)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RiderNotFound,
                              riderName));
            }

            bool isExistMotorcycle = this.motorcycleRepository
                                     .GetAll()
                                     .Any(m => m.Model == motorcycleModel);

            if (!isExistMotorcycle)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.MotorcycleNotFound,
                              motorcycleModel));
            }

            IMotorcycle motorcycle = this.motorcycleRepository
                                     .GetByName(motorcycleModel);

            IRider rider = this.riderRepository
                           .GetByName(riderName);

            rider.AddMotorcycle(motorcycle);

            string result = string.Format(
                OutputMessages.MotorcycleAdded,
                riderName,
                motorcycleModel);

            return(result);
        }