public string CreateMotorcycle(string type, string model, int horsePower) { if (this.motorcycleRepository.GetByName(model) != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle = null; switch (type) { case "Power": motorcycle = new PowerMotorcycle(model, horsePower); break; case "Speed": motorcycle = new SpeedMotorcycle(model, horsePower); break; default: break; } this.motorcycleRepository.Add(motorcycle); return(string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model)); }
public string CreateMotorcycle(string type, string model, int horsePower) { if (this.motorcycleRepository.GetByName(model) != null) { string output = string.Format(ExceptionMessages.MotorcycleExists, model); throw new ArgumentException(output); } if (type == "Speed") { SpeedMotorcycle motorcycle = new SpeedMotorcycle(model, horsePower); this.motorcycleRepository.Add(motorcycle); string result = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); return(result); } else { PowerMotorcycle motorcycle = new PowerMotorcycle(model, horsePower); this.motorcycleRepository.Add(motorcycle); string result = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); return(result); } }
public string CreateMotorcycle(string type, string model, int horsePower) { var listOfMotors = motorRepo.GetAll().ToList(); if (listOfMotors.Any(x => x.Model == model)) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } if (type == "Speed") { var newMotorycle = new SpeedMotorcycle(model, horsePower); motorRepo.Add(newMotorycle); return(string.Format(OutputMessages.MotorcycleCreated, newMotorycle.GetType().Name, model)); } else { var newMotorycle = new PowerMotorcycle(model, horsePower); motorRepo.Add(newMotorycle); return(string.Format(OutputMessages.MotorcycleCreated, newMotorycle.GetType().Name, model)); } }
public string CreateMotorcycle(string type, string model, int horsePower) { if (motorcycleRepository.GetByName(model) != null) { throw new ArgumentException(string.Format(ExceptionMessages.MotorcycleExists, model)); } IMotorcycle motorcycle; if (type == "Power") { motorcycle = new PowerMotorcycle(model, horsePower); motorcycleRepository.Add(motorcycle); message = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); } else if (type == "Speed") { motorcycle = new SpeedMotorcycle(model, horsePower); motorcycleRepository.Add(motorcycle); message = string.Format(OutputMessages.MotorcycleCreated, motorcycle.GetType().Name, motorcycle.Model); } return(message); }